Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nexus 3 as npm repository can't find some dependencies: npm ERR! 404 Not Found:

I am using Nexus 3 as npm private repository. I have a project that requires some dependencies such as: @nodelib/fs.stat, @mrmlnc/readdir-enhanced@^2.2.1.

If I execute the following npm install commands everything works alright:

sudo npm install -g @nodelib/fs.stat
+ @nodelib/[email protected]
added 1 package in 0.481s

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

But I have to configure .npmrc to reference my nexus npm repository this way:

~/.npmrc:

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

Now when I try to install my private project npm install -g generator-myyeomangenerator if fails because it can't download those dependencies.

In fact, now that I have set up my .npmrc config if I directly execute npm install for those dependencies I get a 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

The log file doesn't provide additional info.

Appart from those dependencies, running some other installs work ok event through the npm repo:

sudo npm install -g jav
+ [email protected]
added 71 packages in 9.628s

It seems to be related to the @ naming of the deps, here's another example of failing execution:

npm install -g @angular/[email protected]
npm ERR! code E404
npm ERR! 404 Not Found: @angular/[email protected]

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

How can I fix this?

like image 278
codependent Avatar asked Jun 04 '18 22:06

codependent


2 Answers

Fixed with this custom .npmrc file that uses the public npm repository for those scoped packages that can't be resolved through Nexus:

@angular:registry=https://registry.npmjs.org/
@nodelib:registry=https://registry.npmjs.org/
@mrmlnc:registry=https://registry.npmjs.org/
registry=http://mynexus.com/repository/npmrepo/
like image 106
codependent Avatar answered Sep 21 '22 13:09

codependent


Is Apache running in front of Nexus? By default it won't allow encoded slashes to pass through, this breaks retrieval of npm scoped packages.

To fix it, add the following in your Apache config :

# 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

See more details here: https://issues.sonatype.org/browse/NEXUS-10570

like image 28
rseddon Avatar answered Sep 23 '22 13:09

rseddon