npm windows install globally results in npm ERR! extraneous

I am new to grunt and npm. So I am trying some "cookbook-example" 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. (Ok, some errors I had to figure out, but now I have working npm).

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.

Thanks in advance, Meru

82215 次浏览

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

因为您列出的是全局安装的包,所以会出现很多无关的错误,这些错误可以简单地忽略,因为全局安装的大多数东西都不会出现在项目的 package.json中。

1和2: 这意味着你没有在你的项目的 package.json 文件中列出 jshint,但是它是全局安装的。所以这不是什么大问题。

3: 为了避免这个 无关紧要错误,您可以使用选项 --save运行或重新运行安装。这将自动更新 package.json 文件:

npm install -g jshint --save

或者需要使用 "dependencies": {...}手动更新 package.json 文件

我通过在父包的文件夹中执行 npm update来解决这个问题,它从列表中删除了一些无关的包,然后对剩下的几个包执行 npm uninstall <package>

似乎已经工作,因为我没有得到这样的错误后,这样做。

我把所有的答案结合起来解决了这个问题,首先我在全球范围内安装了这个软件包。

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.

我选择的解决方案是删除本地的,然后全局安装。

npm uninstall packagename
npm install -g packagename

这样我就没有更多的警告,也不会弄乱 package.json 文件。

我的案子,我看到这个‘ npm 错误!在我的 Cygwin 终端里,当我做一个“ npm ls”的时候。我认为这是某种全球性的腐败设置后,有很多修补。我在这里了解到以下意见:

  • “ npm ls”根据当前文件夹的位置提供不同的输出。
  • “ npm ls”尝试检测当前文件夹位置中是否存在“ node _ module”文件夹,并列出这些内容。不是全球性的!
  • 此外,如果当前包含‘ node _ module’的文件夹也有一个 package.json 文件,其中包含的模块较少,则会显示错误。

I‘ rm package.json’和‘ npm ls’不再显示错误消息。所以我说,总是检查当前位置是否存在“ node _ module”文件夹和 package.json 文件,因为这些是优先级在检查中的第一位,如果它们丢失了,检查将继续到父文件夹等等,如果你修改了很多代码片段,那么你可能已经分散在很多很多的 node _ module 文件夹和 package.json 文件中。这里没有什么真正的损坏,不像我们在进行 J2EE Java 开发/Eclipse IDE 时或者在我们必须使用 regedit 来更改 Windows 中的设置时的那些经验。

这是因为您的包不在 package.json 中。如果你加上它,问题就解决了,请看下面的图片:

enter image description here

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.

这种情况发生在使用 dependencies: { "my-module": "file:local-modules/mymodule" }语法时,在名称“ my-module”中有一个输入错误。