无法通过 npm 自动安装类名包(在 package.json 中定义)

Cannot install classnames package (defined in package.json) automatically by npm

我对 NodeJS 很陌生,我在安装 classnames 包时遇到 npm 问题,该包保存到 package.json 文件。

假设我有这个 dependencies 列表:

"dependencies": 
{
    "classnames": "^2.1.2",
    "jquery": "^2.1.3",
    "sleep": "^1.2.0",
},

然后,当我运行npm install时,只安装了jquerysleep进入 node_modules 文件夹,而不是 classnames。但是,如果我 运行 手动 npm install classnames,它会将该包下载到 node_modules 文件夹。

因此,我可以通过此解决方法 运行 我在本地的应用程序,但是当我将代码部署到 heroku 时,它无法以任何方式安装,我的应用程序也无法 运行。

我试过 运行 npm cache clean 但没有用。是来自特定 classnames 包还是其他任何问题?

提前致谢。

终于可以解决这个问题了。这不仅仅是 classnames 包的问题。

解决方案是 运行 npm shrinkwrap 在我在本地安装了所有我想要的包之后。然后提交所有内容(尤其是 npm-shrinkwrap.json 中的更改)并推送到 heroku.

原因已经解释清楚here。快速回顾:

When "npm install" installs a package with a npm-shrinkwrap.json file in the package root, the shrinkwrap file (rather than package.json files) completely drives the installation of that package and all of its dependencies (recursively).