Nexus 3作为npm仓库无法找到一些依赖项:npm ERR!404未找到:

8
我将使用Nexus 3作为npm私有仓库。我有一个需要一些依赖项的项目,例如:@nodelib/fs.stat@mrmlnc/readdir-enhanced@^2.2.1
如果我执行以下npm install命令,一切正常:
sudo npm install -g @nodelib/fs.stat
+ @nodelib/fs.stat@1.1.0
added 1 package in 0.481s

sudo npm install -g @mrmlnc/readdir-enhanced@^2.2.1
+ @mrmlnc/readdir-enhanced@2.2.1
added 3 packages in 2.178s

但是我必须配置.npmrc文件来引用我的nexus npm存储库,如下所示:

~/.npmrc:

registry=http://mynexus.com/repository/npmrepo

现在当我尝试安装我的私有项目npm install -g generator-myyeomangenerator时,它失败了,因为它无法下载这些依赖项。

事实上,现在我已经设置了我的.npmrc配置,如果我直接执行npm install来安装这些依赖项,我会收到404错误:

sudo npm install -g @nodelib/fs.stat
npm ERR! code E404
npm ERR! 404 Not Found: @nodelib/fs.stat@latest

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/myuser/.npm/_logs/2018-06-04T21_55_56_792Z-debug.log

日志文件没有提供额外的信息。

除了这些依赖项,通过npm仓库运行一些其他安装也可以正常工作:

sudo npm install -g jav
+ jav@1.0.2
added 71 packages in 9.628s

这似乎与依赖项的@命名有关,这是另一个执行失败的示例:

npm install -g @angular/common@2.4.10
npm ERR! code E404
npm ERR! 404 Not Found: @angular/common@2.4.10

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/myuser/.npm/_logs/2018-06-04T22_01_02_384Z-debug.log

我该怎样解决这个问题?
2个回答

11

使用这个定制的 .npmrc 文件可以解决那些无法通过 Nexus 解析的作用域包,它会使用公共 npm 存储库:

@angular:registry=https://registry.npmjs.org/
@nodelib:registry=https://registry.npmjs.org/
@mrmlnc:registry=https://registry.npmjs.org/
registry=http://mynexus.com/repository/npmrepo/

1
这是否意味着作用域包无法与Nexus私有注册表一起使用? - danwellman
@danwellman,你找到问题的答案了吗? - luiscla27
1
抱歉,我不记得了 - 这是在以前的工作中,因此是在以前的生命中! - danwellman

9

Apache是否在Nexus前运行?默认情况下,它不允许编码斜杠通过,这会破坏npm作用域包的检索。

要解决此问题,请在Apache配置中添加以下内容:

# Solution for Apache httpd < 2.0.52
AllowEncodedSlashes On

# Solution for Apache httpd 2.0.52 to 2.2.8 
AllowEncodedSlashes NoDecode
# The ProxyPass directive may need the nocanon option, as shown below :
ProxyPass / http://localhost:8081/ nocanon

在这里查看更多详细信息:https://issues.sonatype.org/browse/NEXUS-10570


谢谢提供信息,我认为它前面有一个Apache服务器,我会去检查一下。 - codependent

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接