0

I am trying to install the react-cookie dependency in my react project. The react project is run on a standalone offline network with no internet connection. The dependency is packed into a tarball file and uploaded onto the server. I then run npm install react-cookie-4.0.3.tgz but I then get the following error

ERR! network request to https://registry.npmjs.org/@emotion%2fcore failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

How do I resolve this?

Hazed 2.0
  • 133
  • 2
  • 14
  • Could it be that `react-cookie` has some dependencies, which npm is trying to download as well ? – turbopasi Jan 06 '21 at 18:05
  • However, you should just copy the package into the projects node_modules folder (including all dependencies) and hit `npm install` in the root folder. Should do the trick ( Possible duplicate : https://stackoverflow.com/questions/43064107/how-to-install-npm-package-while-offline) – turbopasi Jan 06 '21 at 18:07
  • How are you building and packaging your application? You shouldn't need to do an npm install for the deployed app. – Dean James Jan 06 '21 at 18:08
  • Does this answer your question? [How to install npm package while offline?](https://stackoverflow.com/questions/43064107/how-to-install-npm-package-while-offline) – turbopasi Jan 06 '21 at 18:10

2 Answers2

2

A possible solution is to copy the node_modules folder you need instead of installing from the server that is offline. So:

  1. Install the package in a computer that is connected to internet (for example your development computer)
  2. copy the node_modules directory in the server that is offline

In this way you don't need to install the package in the server.

If you have something cached on your server you can also consider this option:

https://docs.npmjs.com/cli/v6/using-npm/config#offline

Emanuele Scarabattoli
  • 4,103
  • 1
  • 12
  • 21
  • Should do the trick, I guess it would be also possible to just copy the package to the server's node_modules folder (plus all dependencies) and run `npm install` there – turbopasi Jan 06 '21 at 18:09
  • copying node_modules won't work for packages that require building, especially between different OS – Lukas Liesis Jun 21 '21 at 11:45
0

It is possibly due to the fact that you need to take care of react-cookie dependencies as well.

Try this in machine with internet:

  1. Clear npm cache: npm cache clear

  2. Install package, lets say its x.y.z: npm install -g **package.x.y.z**

  3. Copy cache in to a folder, let's call it whatever (I assume npm cache is in root folder, not absolutely sure about that): cp -R /.npm/* **/cache-whatever-folder**

In machine with no internet:

  1. Take this cache-whatever-folder to the instance with no internet and after that, clean cache and install with it (I won't indicate how to copy the folder :)

npm cache clear

npm install --global --cache **/cache-whatever-folder** --optional --cache-min 99999999999 --shrinkwrap false **package.x.y.z**