Extraneous Package when Installed Locally

node.jsTwitter BootstrapNpm

node.js Problem Overview


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

├─┬ phantomjs@1.9.0-3 extraneous
│ ├── adm-zip@0.2.1
...
npm ERR! extraneous: phantomjs@1.9.0-3 /Users/admin/bootstrap/node_modules/phantomjs
npm ERR! not ok code 0

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

Questions:

  1. Is it because phantomjs not specified in the package.json file?
  2. General question: Can we have any package e.g. phantomjs installed globally and also locally?

node.js Solutions


Solution 1 - node.js

  1. Yes. (Re-installing with npm install wont install phantom.js again.) (Btw.: npm install xxx --save will 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.)

Solution 2 - node.js

  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

will remove all non-required packages.

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

    sudo npm install -g phantomjs

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmoeyView Question on Stackoverflow
Solution 1 - node.jsTheHippoView Answer on Stackoverflow
Solution 2 - node.jsJamil AbdallahView Answer on Stackoverflow