0

I would like to create a new npm project with a few modules on a machine without internet access.

This machine has various older projects each with a node_modules folder with lots of modules in there.

Can I somehow tell npm to use all these modules to create the new project instead of going out to the internet?

When I just issue

$ npm install browser-sync gulp gulp-sass

npm obviously tries to download these modules from the internet instead of gathering them from the various node_modules directories on the machine where the modules already exist!

halloleo
  • 9,216
  • 13
  • 64
  • 122
  • Do you have _all_ dependencies and all of _their_ dependencies, and so on? It's definitely theoretically possible to create the node_modules tree by hand, but it'll be an awful lot of work, and you'll have to rm your package-lock.json or yarn.lock. You can get a list of all required packages with `grep '"node_modules/' package-lock.json` in your project. – Zac Anger Dec 05 '22 at 01:47
  • You could also try setting `NODE_PATH` to all the various `node_modules` directories (separated by a colon, like PATH, or semicolon on Windows). I have no idea if that will work, but it's worth a shot. – Zac Anger Dec 05 '22 at 01:51
  • I guess I have all dependencies. Just was hoping npm can do the copying of the modules plus the necessary additions to the `package.json` for me -- as it does when installing over the internet. – halloleo Dec 05 '22 at 03:59
  • No easy way to make that happen, no. If you have remote or physical access, you could always simply `npm i` on a computer that has outside internet access, ZIP it up, and get it to that machine. – Zac Anger Dec 05 '22 at 04:07

0 Answers0