【问题标题】:npm @types and TypeScript versionnpm @types 和 TypeScript 版本
【发布时间】:2019-02-22 13:21:54
【问题描述】:

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

我们使用的是 TypeScript,所以需要为一些 npm 包安装 @types,所以在我们的 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.js typescript npm


    【解决方案1】:

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

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

    【讨论】:

    • 啊,好吧,所以你认为问题出在包锁定文件上?
    • 1️⃣将package-lock.json文件添加到git。 2️⃣为每个环境删除node_modules。 3️⃣跑npm install?你有重复性!
    猜你喜欢
    • 2017-12-04
    • 2017-03-07
    • 2016-09-29
    • 2019-04-07
    • 2016-12-29
    • 2017-08-21
    • 2018-07-11
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多