代码之家  ›  专栏  ›  技术社区  ›  JacobTheDev

`npm install`总是安装package.json中的所有内容

  •  0
  • JacobTheDev  · 技术社区  · 6 年前

    我正在尝试设置一些依赖于几个节点模块的CI测试,但不需要在package.json中安装所有内容。我想我可以这样做:

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

    但是,这样做仍然会安装我的 devDependencies 在package.json中。我如何告诉NPM忽略我的package.json,只安装我特别告诉它的东西?


    编辑:为了更好地演示我遇到的问题,我删除了 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
    
    2 回复  |  直到 6 年前
        1
  •  16
  •   JacobTheDev    6 年前

    我已经弄明白了为什么会这样;显然如果你有 package-lock.json ,NPM总是在那里安装所有东西,而不管您传递的标志是什么。解决办法是 --no-package-lock 旗帜。

    npm install --no-package-lock --no-save --quiet stylelint-config-standard stylelint-order stylelint-scss
    
        2
  •  -1
  •   dvsoukup    6 年前

    根据npm文档,您只能安装 dependencies ,没有别的。 https://docs.npmjs.com/cli/install

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

    注意:在添加 对项目的依赖性。

    所以,快跑吧 npm install --production