node.js 本地安装时的无关包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16252750/
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 14:20:16  来源:igfitidea点击:

Extraneous Package when Installed Locally

node.jstwitter-bootstrapnpm

提问by moey

I was trying to install phantomjsin order to make testTwitter Bootstrap. After I had installed it locally i.e. npm install phantomjs, it reported that the package was extraneous.

我试图安装phantomjs以便make testTwitter Bootstrap。我在本地 ie 安装它后npm install phantomjs,它报告说这个包是无关紧要的。

├─┬ [email protected] extraneous
│ ├── [email protected]
...
npm ERR! extraneous: [email protected] /Users/admin/bootstrap/node_modules/phantomjs
npm ERR! not ok code 0

However, when phantomjswas installed globally i.e. npm install phantomjs -g, it worked fine i.e. no extraneous error reported.

然而,当phantomjs被全局安装时npm install phantomjs -g,它工作正常,即没有报告无关的错误。

Questions:

问题:

  1. Is it because phantomjsnot specified in the package.jsonfile?
  2. General question: Can we have any package e.g. phantomjsinstalled globally and also locally?
  1. 是因为package.json文件中没有指定phantomjs吗?
  2. 一般问题:我们可以在全球和本地安装任何包,例如phantomjs吗?

回答by TheHippo

  1. Yes. (Re-installing with npm installwont install phantom.js again.) (Btw.: npm install xxx --savewill automatically add xxx to the package.json)
  2. Yes. Local package versions are preferred over global ones. (Although you need some path handling for executables.)
  1. 是的。(重新安装npm install不会再次安装phantom.js。)(顺便说一句:npm install xxx --save会自动将xxx添加到package.json中)
  2. 是的。本地包版本优于全局包版本。(尽管您需要对可执行文件进行一些路径处理。)

回答by Jamil Abdallah

  1. phantomjs should be included in your local .json package(manually editing it or using --save command see TheHippo's answer). If it is installed somewhere and you don't need it use the prune command

    npm prune

  1. phantomjs 应该包含在您本地的 .json 包中(手动编辑它或使用 --save 命令查看 TheHippo 的答案)。如果它安装在某个地方并且您不需要它,请使用 prune 命令

    npm prune

will remove all non-required packages.

将删除所有不需要的包。

  1. To install an item both locally and globally use:

    sudo npm install -g phantomjs

  1. 要在本地和全局安装项目,请使用:

    sudo npm install -g phantomjs