npm windows install global 导致 npm ERR!无关的

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

npm windows install globally results in npm ERR! extraneous

windowsgruntjsnpm

提问by Meru

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).

我是 grunt 和 npm 的新手。所以我正在网站上尝试一些“食谱示例”' http://tech.pro/tutorial/1190/package-managers-an-introductory-guide-for-the-uninitiated-front-end-developer#front_end_developers' . 你现在不应该去那里看看,但我认为分享这个网站可能会很好。到目前为止一切顺利,直到涉及到全局安装。(好吧,我必须弄清楚一些错误,但现在我可以使用 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

  1. 创建测试目录 grunttest

  2. 在该目录中:

    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
 [email protected] C:\Program Files\nodejs\node_modules\npm\node_modules\jshint
 ├── [email protected]
 ├── [email protected]
 ├── [email protected]
 ├── [email protected]
 ├── [email protected] ([email protected], [email protected])
 ├── [email protected] ([email protected])
 └── [email protected] ([email protected], [email protected], [email protected], [email protected])

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

我刚刚意识到 304,这应该没问题,因为只是说自上次安装(几分钟前)以来没有修改资源。

Checking if the jshint exists with:

检查 jshint 是否存在:

`npm -global list`

Output:

输出:

[email protected] C:\Program Files\nodejs\node_modules\npm
├── [email protected]
├── [email protected]
├─...
├──
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected] extraneous
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   └─... ├── [email protected]
├── [email protected]
└── [email protected]

**npm ERR! extraneous: [email protected] 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?
  1. 为什么我得到 npm ERR!外来的……?
  2. 这是什么意思?
  3. 我该如何解决这个问题?

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.

我在 Windows 机器 Windows 7 上,使用 cygwin 作为 shell。试图只是 jshint ( jshint someTestfile.js) 当然是行不通的。

Thanks in advance, Meru

提前致谢,梅鲁

回答by Kyle Robinson Young

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

npm ERR! extraneous表示已安装包但未在项目的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.

由于您要列出已全局安装的软件包,它会给您带来许多可以简单忽略的无关错误,因为全局安装的大多数内容不会在您项目的package.json.

回答by rebe100x

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.

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

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

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

npm install -g jshint --save

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

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

回答by metakermit

I resolved this by doing an npm updatein 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.

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

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

似乎有效,因为这样做后我没有收到任何错误。

回答by scorer

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.

由于 npm 也全局安装了这个打包文件,但没有将其添加到我的本地 package.json 文件中,因此我必须对此做一些事情。

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.

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

回答by typelogic

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 ERR!当我执行 'npm ls' 时,我的 cygwin 终端中出现无关的消息。经过大量修补后,我认为这是某种全局损坏的设置。我在这里了解到以下观察结果:

  • '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.
  • 'npm ls' 根据您当前的文件夹位置提供不同的输出。
  • “npm ls”尝试检测当前文件夹位置中是否存在“node_modules”文件夹,并列出这些内容。不是全球的!
  • 此外,如果包含“node_modules”的当前文件夹也有包含此处列出的较少模块的 package.json 文件,则会显示错误。

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.

我 'rm package.json' 和 'npm ls' 不再显示错误消息。所以我说,总是检查当前位置是否存在“node_modules”文件夹和 package.json 文件,因为这些在检查中优先考虑,如果这些丢失,检查继续到父文件夹,依此类推,如果你修改了很多代码片段,那么你可能已经散布在很多 node_modules 文件夹和 package.json 文件中。与我们在进行 J2EE Java 开发 / eclipse IDE 或在我们必须使用 regedit 更改 Windows 中的设置时的那些经历不同,这里没有真正损坏的东西。

回答by youen

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

就我而言,这是因为其package.json文件中的包名称package.json与依赖模块的 中列出的依赖名称不同。我的错误,因为它是我创建的一个新模块,但很难发现,因为 npm 不会提供任何线索。

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

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

回答by Narendra Sagadevan

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:

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

enter image description here

在此处输入图片说明