无法使用“npm install”在 Node.js 中安装任何软件包

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

Can't install any packages in Node.js using "npm install"

node.jsnpm

提问by Ido Cohn

I'm new to Node.js, and I'm going through a few tutorials. For some reason, I can't install any new node modules.

我是 Node.js 的新手,我正在学习一些教程。出于某种原因,我无法安装任何新的节点模块。

I am using: Mac OSX 10.7.4, Node v. 0.8.6, NPM v. 1.1.48.

我使用: 的Mac OSX 10.7.4节点U 0.8.6。 NPM v 1.1.48。

I run npm install X and I always get a

我运行 npm install X 并且我总是得到一个

npm ERR! fetch failed https://registry.npmjs.org/-/X
npm ERR! Error: 404 Not Found

When I actually go to the npmjs registry, I can see the project page, but no matter which tarball link I hit, it's always the same:

当我真正进入 npmjs 注册表时,我可以看到项目页面,但是无论我点击哪个 tarball 链接,它总是相同的:

{
    "error": "not_found",
    "reason": "document not found"
}

For example, I tried installing fsby running npm install fsand I get:

例如,我尝试安装FS运行NPM安装FS和获取:

npm http GET https://registry.npmjs.org/fs
npm http 200 https://registry.npmjs.org/fs
npm http GET https://registry.npmjs.org/-/fs-0.0.0.tgz
npm http 404 https://registry.npmjs.org/-/fs-0.0.0.tgz
npm ERR! fetch failed https://registry.npmjs.org/-/fs-0.0.0.tgz
npm ERR! Error: 404 Not Found
npm ERR!     at null.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/fetch.js:47:16)
npm ERR!     at EventEmitter.emit (events.js:115:20)
npm ERR!     at WriteStream.flush (fs.js:1514:12)
npm ERR!     at fs.close (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:92:5)
npm ERR!     at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Darwin 11.4.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "fs"
npm ERR! cwd /Users/comocomo/Documents/workspace/nodeTest
npm ERR! node -v v0.8.6
npm ERR! npm -v 1.1.48
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/comocomo/Documents/workspace/nodeTest/npm-debug.log
npm ERR! not ok code 0

I tried fs, fs-extra, express, and formidable, all giving me the same 404 response. There must be something wrong on my part, I'm pretty sure the whole registry is not broken.

我尝试了 fs、fs-extra、express 和强大的,都给了我相同的 404 响应。我一定有问题,我很确定整个注册表没有损坏。

Am I using an old registry? Should I change it in my config file? I honestly would rather not start installing things manually, and I'm sure it's just a small configuration issue.

我使用的是旧注册表吗?我应该在我的配置文件中更改它吗?老实说,我宁愿不开始手动安装东西,而且我确定这只是一个小配置问题。

Thanks!

谢谢!

回答by Ian S Williams

I found the there is a certificate expired issue with:

我发现有一个证书过期问题:

npm set registry https://registry.npmjs.org/

So I made it http, not https :-

所以我把它设为 http,而不是 https :-

npm set registry http://registry.npmjs.org/

And have no problems so far.

并且到目前为止没有任何问题。

回答by framp

The repository is not down, it looks like they've changed how they host files (I guess they have restored some old code):

存储库没有关闭,看起来他们已经改变了他们托管文件的方式(我猜他们已经恢复了一些旧代码):

Now you have to add the /package-name/ before the -

现在你必须在 - 之前添加 /package-name/

Eg:

例如:

http://registry.npmjs.org/-/npm-1.1.48.tgz
http://registry.npmjs.org/npm/-/npm-1.1.48.tgz

There are 3 ways to solve it:

有3种方法可以解决:

  • Use a complete mirror:
  • Use a public proxy:

    --registry http://165.225.128.50:8000

  • Host a local proxy:

    https://github.com/hughsk/npm-quickfix

  • 使用完整的镜像:
  • 使用公共代理:

    --registry http://165.225.128.50:8000

  • 托管本地代理:

    https://github.com/hughsk/npm-quickfix

git clone https://github.com/hughsk/npm-quickfix.git
cd npm-quickfix
npm set registry http://localhost:8080/
node index.js
git clone https://github.com/hughsk/npm-quickfix.git
cd npm-quickfix
npm set registry http://localhost:8080/
node index.js

I'd personally go with number 3 and revert to npm set registry http://registry.npmjs.org/as soon as this get resolved.

我个人会选择 3 号,并在npm set registry http://registry.npmjs.org/解决此问题后立即恢复。

Stay tuned here for more info: https://github.com/isaacs/npm/issues/2694

请继续关注这里以获取更多信息:https: //github.com/isaacs/npm/issues/2694

回答by Elad

Npm repository is currently down. See issue #2694on npm github

Npm 存储库当前已关闭。请参阅npm github 上的问题#2694

EDIT:
To use a mirror in the meanwhile:

编辑
同时使用镜子:

 npm set registry http://ec2-46-137-149-160.eu-west-1.compute.amazonaws.com

you can reset this later with:

您可以稍后使用以下方法重置:

 npm set registry https://registry.npmjs.org/

source

来源

回答by Akash Kumar

This error might also occur due to proxy settings, once check that your proxy allow the access to npm commands.

此错误也可能由于代理设置而发生,一旦检查您的代理是否允许访问 npm 命令。

It worked for me quite well.

它对我很有效。

回答by Tobias Strebitzer

npm set registry http://85.10.209.91/

(this proxy fetches the original data from registry.npmjs.org and manipulates the tarball urls to fix the tarball file structure issue).

(此代理从 registry.npmjs.org 获取原始数据并操作 tarball url 以修复 tarball 文件结构问题)。

The other solutions seem to have outdated versions.

其他解决方案似乎有过时的版本。