Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

node.js - How to install an npm package on a standalone offline server?

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...