npm @types和TypeScript版本

时间:2018-09-18 13:27:48

标签: node.js typescript npm

因此,我们存在一个问题,即通过npm在构建计算机上安装的文件与在开发人员计算机上本地使用的文件不同。

我们正在使用TypeScript,因此要求为某些npm软件包安装@types,因此在package.json文件中,我们有...

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

在本地重新安装npm时,这会拉下types文件,并在顶部的文件中显示;

// 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,但是有些不正确。在本地,我们现在看到的行为与发布到实时环境中的行为不同。

有人有什么主意吗?

1 个答案:

答案 0 :(得分:1)

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

您应将package-lock.json / yarn.lock存储在git存储库中,以确保可重复性。