8

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/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

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
+ jav@1.0.2
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/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

How can I fix this?

codependent
  • 23,193
  • 31
  • 166
  • 308

2 Answers2

11

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/
codependent
  • 23,193
  • 31
  • 166
  • 308
9

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

ojathelonius
  • 685
  • 8
  • 26
rseddon
  • 5,082
  • 15
  • 11