P3anuts
P3anuts

Reputation: 471

Make npm install work without internet connection

In our company we have a local Sonatype Nexus which we use to cache Npm, Maven, Nuget etc. It is set up as a proxy for public repos and has all the node_modules cached. However, the npm modules them self still fetch other artifacts from the internet and this might cause a problem since we want to have everything that is required to build under our control.

For instance, if we cut the servers internet connection we get these errors during npm install:

    06:57:49 D:\jenkins\workspace\AnxNT.Archetype\Web>npm install 
06:58:05 npm WARN install Couldn't install optional dependency: Unsupported
07:00:31 npm ERR! fetch failed https://github.com/rase-/node-XMLHttpRequest/archive/a6b6f2.tar.gz
07:00:31 npm WARN retry will retry, error on last attempt: Error: connect ETIMEDOUT 192.30.252.131:443
07:02:55 npm ERR! fetch failed https://github.com/rase-/node-XMLHttpRequest/archive/a6b6f2.tar.gz
07:02:55 npm WARN retry will retry, error on last attempt: Error: connect ETIMEDOUT 192.30.252.131:443
07:06:08 npm ERR! fetch failed https://github.com/rase-/node-XMLHttpRequest/archive/a6b6f2.tar.gz
07:06:08 npm ERR! Windows_NT 6.3.9600

Is there anyway to solve this? Help and tips greatly appreciated.

Upvotes: 0

Views: 1931

Answers (1)

Manfred Moser
Manfred Moser

Reputation: 29912

This sort of reaching beyond the registry is imho a weakness of the NPM system and the validation of packages.

There are really only two options. Both of them are kind of hard to implement.

  1. You could intercept all external URL calls and rewrite them to the equivalent local resources. Problem of course is that there are potentially a LOT of them and they change as well.

  2. The other thing you could do is to fork those npm packages that reach out like that, change the links to something locally valid or some replacement and republish them to your inhouse npm repository. Given the right order in the repository group or the usage of a different version or name for the package you can then use it instead.

Unfortunately there is nothing better I can think of. No other real solutions exists to my knowledge.

Further tips are also available in the Sonatype support site.

Upvotes: 1

Related Questions