node.js npm install 不会安装 devDependencies

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34700610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:45:04  来源:igfitidea点击:

npm install won't install devDependencies

node.jsnpm

提问by Tristan Tzara

On windows for some reason when I run npm installit won't install devDependencies. AFAIK it should. If I run npm install --devdevDependenciesare installed. I don't understand why npm installdoesn't install devDependenciestoo, but installs only dependencies. What could be the reason? How can I fix it?

在 Windows 上,由于某种原因,当我运行npm install它时,它不会安装devDependencies。AFAIK它应该。如果我运行npm install --devdevDependencies安装。我不明白为什么npm install不安装devDependencies,而是只安装依赖项。可能是什么原因?我该如何解决?

Maybe something is wrong with my package.json? It is listed below if it may be helpful:

也许我的package.json 有问题?如果它可能有帮助,它列在下面:

{
  "name": "try-brunch",
  "version": "0.1.0",
  "private": "true",
  "devDependencies": {
    "brunch": "^2.0.4",
    "cssnano-brunch": "^1.1.5",
    "javascript-brunch": "^1.8.0",
    "sass-brunch": "^1.9.2",
    "uglify-js-brunch": "^1.7.8"
  },
  "dependencies": {
    "jquery": "^2.1.4"
  }
}

回答by arcseldon

Check the NPM docs for install

检查 NPM 文档以进行安装

With the --productionflag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies."

The --only={prod[uction]|dev[elopment]}argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV."

使用该--production标志(或当 NODE_ENV 环境变量设置为生产时),npm 将不会安装 devDependencies 中列出的模块。”

--only={prod[uction]|dev[elopment]}参数将导致只安装 devDependencies 或只安装非 devDependencies,而不管 NODE_ENV。”

Have you tried

你有没有尝试过

npm install --only=dev

If you are worried that your package.jsonmight be incorrect, best thing to do is this. Create a new folder, and run:

如果你担心你的package.json可能不正确,最好的办法就是这样做。创建一个新文件夹,然后运行:

npm init --yes

Then:

然后:

npm install --save-dev brunch@^2.0.4
npm install --save-dev cssnano-brunch@^1.1.5
npm install --save-dev javascript-brunch@^1.8.0
npm install --save-dev sass-brunch@^1.9.2
npm install --save-dev uglify-js-brunch@^1.7.8
npm install jquery@^2.1.4 --save

And you should be good to go! Otherwise, will keep posting other options.

你应该很高兴去!否则,将继续发布其他选项。

Check your npm configuration:

检查您的 npm 配置:

npm config list

npm gets its config settings from the command line, environment variables, and npmrc files. So check environment variables, and the npmrcfile.

npm 从命令行、环境变量和 npmrc 文件中获取其配置设置。所以检查环境变量和npmrc文件。

Still failing?

还是失败?

Ok, create a new folder, ideally somewhere else on your filesystem. ie. not in same folder hierarchy. For instance, C:\myNewFolder - the closer to the base C: drive the better.

好的,创建一个新文件夹,最好是文件系统上的其他位置。IE。不在同一个文件夹层次结构中。例如,C:\myNewFolder - 离基本 C: 驱动器越近越好。

Then run:

然后运行:

npm init --yes

Now run:

现在运行:

npm install underscore --save

and finally:

最后:

npm install mocha --save-dev

Does everything work as expected?

一切都按预期工作吗?

What I am trying to do is understand whether your problem is global, or something local to the previous folder and dependencies.

我想要做的是了解您的问题是全局性的,还是先前文件夹和依赖项的本地问题。

回答by Shawn Mclean

Check if npm config production value is set to true. If this value is true, it will skip over the dev dependencies.

检查 npm config production 值是否设置为 true。如果此值为 true,它将跳过开发依赖项。

Run npm config get production

npm config get production

To set it: npm config set -g production false

要设置它: npm config set -g production false

回答by Nir Levy

make sure you don't have env variable NODE_ENVset to 'production'.

确保您没有将 env 变量NODE_ENV设置为“生产”。

If you do, dev dependencies will not be installed without the --devflag

如果这样做,则不会在没有--dev标志的情况下安装开发依赖项

回答by Nir Levy

I had a package-lock.jsonfile from an old version of my package.json, I deleted that and then everything installed correctly.

我有一个package-lock.json旧版本的 package.json 文件,我删除了它,然后一切都正确安装了。

回答by obsessiveprogrammer

I had a similar problem. npm install --only=devdidn't work, and neither did npm rebuild. Ultimately, I had to delete node_modulesand package-lock.jsonand run npm installagain. That fixed it for me.

我有一个类似的问题。 npm install --only=dev没有用,也没有npm rebuild。最终,我不得不删除node_modules并再次package-lock.json运行npm install。那为我修好了。

回答by Ale

You can use the short way for installation dependencies only for development as follows:

您可以使用仅用于开发的安装依赖项的简短方式,如下所示:

npm i -D <dependencies-names>

回答by Alex Gray

Make sure your package.jsonis valid...

确保您package.json的有效...

I had the following error...

我有以下错误...

npm WARN Invalid name: "blah blah blah"

npm WARN Invalid name: "blah blah blah"

and that, similarly, caused devDependenciesnot to be installed.

并且,同样,导致devDependencies未安装。

FYI, changing the package.json"name" to blah-blah-blahfixed it.

仅供参考,更改package.json“名称”以blah-blah-blah修复它。

回答by Phat Tran Ky

I have the same issue because I set the NODE_ENV=productionwhile building Docker. Then I add one more npm install --only=dev. Everything works fine. I need the devDependencies for building TypeSciprt modules

我有同样的问题,因为我NODE_ENV=production在构建 Docker 时设置了。然后我再添加一个npm install --only=dev。一切正常。我需要 devDependencies 来构建 TypeSciprt 模块

RUN npm install
RUN npm install --only=dev