首页 > 解决方案 > npm @types 和 TypeScript 版本

问题描述

所以我们有一个问题,即在我们的构建机器上通过 npm 安装的文件与在我们开发人员的机器上本地使用的文件不同。

我们正在使用 TypeScript,所以需要@types为一些 npm 包安装,所以在我们的 package.json 文件中,我们有......

"dependencies": {
    "react-autosuggest": "^9.3.4"
}
"devDependencies": {        
    "@types/react-autosuggest": "^9.3.3"
}

在本地安装新的 npm 时,这是下拉类型文件,并在顶部的文件中显示;

// Type definitions for react-autosuggest 9.3
// Project: http://react-autosuggest.js.org/
// Definitions by: Nicolas Schmitt <https://github.com/nicolas-schmitt>
//                 Philip Ottesen <https://github.com/pjo256>
//                 Robert Essig <https://github.com/robessog>
//                 Terry Bayne <https://github.com/tbayne>
//                 Christopher Deutsch <https://github.com/cdeutsch>
//                 Kevin Ross <https://github.com/rosskevin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6

但是,构建服务器上的版本是;

// Type definitions for react-autosuggest 9.3
// Project: http://react-autosuggest.js.org/
// Definitions by: Nicolas Schmitt <https://github.com/nicolas-schmitt>
//                 Philip Ottesen <https://github.com/pjo256>
//                 Robert Essig <https://github.com/robessog>
//                 Terry Bayne <https://github.com/tbayne>
//                 Christopher Deutsch <https://github.com/cdeutsch>
//                 Kevin Ross <https://github.com/rosskevin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

注意 TypeScript 的版本差异。

因此,无论出于何种原因,文件类型似乎都是相同的 9.3,但有些地方不太对劲。在本地,我们现在看到不同的行为与发布到实时环境的内容。

有人有什么想法吗?

标签: node.jstypescriptnpm

解决方案


文件package.json不存储具有子依赖项和版本的所有依赖项树。在 Node.js 生态系统中,有package-lock.json/ yarn.lock

您应该将package-lock.json/存储yarn.lock在 git 存储库中以实现可重复性。


推荐阅读