簡體   English   中英

`npm install`總是從package.json安裝所有內容

[英]`npm install` always installs everything from package.json

我試圖建立一些依賴於幾個Node模塊的CI測試,但不需要在package.json中安裝所有內容。 我想我可以這樣做:

npm install --no-save eslint stylelint stylelint-config-standard stylelint-order stylelint-scss

但是,這樣做仍然將我的devDependencies中的所有內容安裝在package.json中。 我怎樣才能告訴NPM忽略我的package.json,而只安裝我專門告訴它的內容?


編輯:為了更好地說明我node_modules的問題,我從我的一個項目中刪除了node_modules ,並嘗試運行npm install --no-save mkdirp mkdirp是一個非常簡單的模塊,具有一個依賴性,但是從下面的輸出中可以看到,NPM繼續進行,仍然將所有內容安裝在我的package.json

jacob@RYZEN:~/Repositories/new-site$ npm install --no-save mkdirp

> puppeteer@1.8.0 install /mnt/c/Users/Jacob/Repositories/new-site/node_modules/puppeteer
> node install.js

Downloading Chromium r588429 - 103.7 Mb [====================] 100% 0.0s
Chromium downloaded to /mnt/c/Users/Jacob/Repositories/new-site/node_modules/puppeteer/.local-chromium/linux-588429

> node-sass@4.9.3 install /mnt/c/Users/Jacob/Repositories/new-site/node_modules/node-sass
> node scripts/install.js

Cached binary found at /home/jacob/.npm/node-sass/4.9.3/linux-x64-57_binding.node

> gifsicle@3.0.4 postinstall /mnt/c/Users/Jacob/Repositories/new-site/node_modules/gifsicle
> node lib/install.js

  ✔ gifsicle pre-build test passed successfully

> jpegtran-bin@3.2.0 postinstall /mnt/c/Users/Jacob/Repositories/new-site/node_modules/jpegtran-bin
> node lib/install.js

  ✔ jpegtran pre-build test passed successfully

> optipng-bin@3.1.4 postinstall /mnt/c/Users/Jacob/Repositories/new-site/node_modules/optipng-bin
> node lib/install.js

  ✔ optipng pre-build test passed successfully

> pngquant-bin@3.1.1 postinstall /mnt/c/Users/Jacob/Repositories/new-site/node_modules/pngquant-bin
> node lib/install.js

  ✔ pngquant pre-build test passed successfully

> node-sass@4.9.3 postinstall /mnt/c/Users/Jacob/Repositories/new-site/node_modules/node-sass
> node scripts/build.js

Binary found at /mnt/c/Users/Jacob/Repositories/new-site/node_modules/node-sass/vendor/linux-x64-57/binding.node
Testing binary
Binary is fine

> swiper@4.3.5 postinstall /mnt/c/Users/Jacob/Repositories/new-site/node_modules/swiper
> node -e "console.log('\u001b[35m\u001b[1mLove Swiper? Support Vladimir\'s work by donating or pledging on patreon:\u001b[22m\u001b[39m\n > \u001b[32mhttps://patreon.com/vladimirkharlampidi\u001b[0m\n')"

Love Swiper? Support Vladimir's work by donating or pledging on patreon:
 > https://patreon.com/vladimirkharlampidi

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ mkdirp@0.5.1
added 1969 packages from 803 contributors and audited 24004 packages in 201.431s
found 21 vulnerabilities (4 low, 8 moderate, 9 high)
  run `npm audit fix` to fix them, or `npm audit` for details

我已經弄清楚了為什么會這樣。 顯然,如果您有package-lock.json ,則NPM始終在其中安裝所有內容,而不管您傳遞的標志如何。 解決方案是--no-package-lock標志。

npm install --no-package-lock --no-save --quiet stylelint-config-standard stylelint-order stylelint-scss

根據npm文檔,您只能安裝dependencies ,而不能安裝其他任何項。 https://docs.npmjs.com/cli/install

使用--production標志(或將NODE_ENV環境變量設置為production時),npm將不會安裝devDependencies中列出的模塊。

注意:--production標志在向項目添加依賴項時沒有特殊含義。

因此,只需運行npm install --production

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM