122

I am trying some "cookbook-examples" on the site 'http://tech.pro/tutorial/1190/package-managers-an-introductory-guide-for-the-uninitiated-front-end-developer#front_end_developers'. You should not have to look there now, but I thought it could be good to share the site. So far so good, til it comes to the global installing.

When it comes to the point trying to install something globally I get stuck.

What I did so far for testing globally installing some package:

  1. Created test-directory grunttest

  2. Inside that directory:

    npm install -g jshint

Output I can see:

 npm http GET https://registry.npmjs.org/jshint
 npm http 304 https://registry.npmjs.org/jshint
 ...
 npm http 304 https://registry.npmjs.org/string_decoder
 C:\Program Files\nodejs\node_modules\npm\jshint -> C:\Program Files\nodejs\node_modules\npm\node_modules\jshinnt
 jshint@2.4.4 C:\Program Files\nodejs\node_modules\npm\node_modules\jshint
 ├── console-browserify@0.1.6
 ├── exit@0.1.2
 ├── underscore@1.4.4
 ├── shelljs@0.1.4
 ├── minimatch@0.2.14 (sigmund@1.0.0, lru-cache@2.5.0)
 ├── cli@0.4.5 (glob@3.2.9)
 └── htmlparser2@3.3.0 (domelementtype@1.1.1, domutils@1.1.6, domhandler@2.1.0, readable-stream@1.0.26-2)

I just realize the 304, which should be ok, due to just says the resource was not modified since last installation (few minutes before).

Checking if the jshint exists with:

`npm -global list`

Output:

npm@1.4.3 C:\Program Files\nodejs\node_modules\npm
├── abbrev@1.0.4
├── ansi@0.2.1
├─...
├──
├── graceful-fs@2.0.2
├── inherits@2.0.1
├── ini@1.1.0
├─┬ init-package-json@0.0.14
│ └── promzard@0.2.1
├─┬ jshint@2.4.4 extraneous
│ ├─┬ cli@0.4.5
│ │ └─┬ glob@3.2.9
│ │   └── inherits@2.0.1
│ ├── console-browserify@0.1.6
│ ├── exit@0.1.2
│ ├─┬ htmlparser2@3.3.0
│ │ ├── domelementtype@1.1.1
│ │ ├── domhandler@2.1.0
│ │ ├── domutils@1.1.6
│ │ └─┬ readable-stream@1.0.26-2
│ │   └─... ├── text-table@0.2.0
├── uid-number@0.0.3
└── which@1.0.5

**npm ERR! extraneous: jshint@2.4.4 C:\Program Files\nodejs\node_modules\npm\node_modules\jshint npm**

Questions:

  1. Why do I get npm ERR! extraneous ...?
  2. What does it mean?
  3. How can I resolve this issue?

Information:

I am on a windows-machine Windows 7, using cygwin as shell. trying to just the jshint (jshint someTestfile.js) of course does not work.

7 Answers 7

216

npm ERR! extraneous means a package is installed but is not listed in your project's package.json.

Since you're listing packages that have been installed globally, it's going to give you a lot of extraneous errors that can be simply ignored because most things installed globally will not be in your project's package.json.

7
  • 1
    hi! Thanks for the answer. Does this mean also, that I acutally should be able to execute the "jshint", correct?
    – Meru
    Mar 25, 2014 at 21:26
  • Correct. Running jshint myfile.js should run jshint on myfile.js. Mar 26, 2014 at 4:07
  • 1
    Ah I see. With Grunt, everything goes through tasks. You would load and configure the grunt-contrib-jshint task in your Gruntfile.js. The only thing you install globally is npm i grunt-cli -g which gives you access to run the grunt command to run a Gruntfile.js. See this guide for more info: gruntjs.com/getting-started Mar 28, 2014 at 17:38
  • 8
    If you have extraneous libraries saved locally (not globally) you can run npm prune to get rid of them.
    – krx
    Oct 19, 2015 at 17:40
  • 2
    @KyleRobinsonYoung: How about mentioning this in answer. You can remove all unused package using npm prune --your-env
    – geek_guy
    Nov 15, 2015 at 14:58
22

1 & 2: It means you don't have the jshint listed in your project's package.json file but that it is globally installed. So it is not a big problem.

3: To avoid this extraneous error, you can run or re-run the install with the option --save . This will update automatically you package.json file :

npm install -g jshint --save

Or need to update manually your package.json file with a "dependencies": {...}

2
  • in ma cases works only with local with no global duplicate
    – Bruno
    Jun 22, 2015 at 20:11
  • 3
    --save doesn't work together with -g. The global package list doesn't have a package.json. Dec 20, 2016 at 20:41
5

I resolved this by doing an npm update in the parent package's folder which removed some of the extraneous packages from the list and then did npm uninstall <package> for the remaining few.

Seems to have worked, as I'm getting no errors after doing this.

3

I solved it by combining all the answers. At first I installed the package globally.

npm install -g packagename --save

Since npm installed this packaged as well globally but did not add it to my local package.json file, I had to do something about it.

I choose, the solution to remove the local one and then install it globally.

npm uninstall packagename
npm install -g packagename

This way I have no more warnings and do not mess up the package.json file.

1
  • Plus 100. I had to uninstall locally and install globally. Sep 9, 2016 at 17:40
1

I my case, I saw this 'npm ERR! extraneous' message in my cygwin terminal when i did an 'npm ls'. I thought this was some sort of a globally corrupted setup after having lots of tinkering. I learn the following observations here:

  • 'npm ls' gives different outputs depending on what is your current folder location.
  • 'npm ls' tries to detect the presence of a 'node_modules' folder in the current folder location, and list out those contents. NOT the global ones!
  • Furthermore, if the current folder containing 'node_modules' also has a package.json file containing fewer modules listed here, then the error shows.

I 'rm package.json' and 'npm ls' no longer shows error message. So I say, that always check the current location for the presence of 'node_modules' folder and the package.json file because these are prioritize first in the check and if these are missing, the check continues to to the parent folder and so on, and if you have tinkered a lot of code snippets a lot, then you may have scattered around lots and lots of node_modules folder and package.json file. Nothing is really corrupted here, unlike those experiences we have when doing J2EE Java development / eclipse IDE or during the days when we have to use regedit to change settings in Windows.

1

In my case it was because the package name in its package.json file was not the same as the depency name listed in the package.json of the dependent module. My error, since it's a new module I created, but hard to spot, since npm won't give any clue.

This happened when using the dependencies: { "my-module": "file:local-modules/mymodule" } syntax, with a typo in the name "my-module".

0

This is due to the fact that your package is not in your package.json. If you add it, the problem will be solved, please look at the image below:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.