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?
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/
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With