Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs/npm: How to reinstall/recompile copied app packages

Setup:

  • A VM with an Internet connection where npm install will be executed to install all the app dependencies. The result will be a folder with the app and its dependencies in node_modules.

  • Between the app modules is fi: mongoose, which on installation time uses node-gyp to compile a native BSON extension.

  • The app folder is copied to another VM without an Internet conection and it is fully functional, but then the compiled extensions don't work but its .js fallbacks does.

Question:

How can I reinstall/recompile/regenerate all the app modules on the new VM without an Internet conection?

like image 936
Diosney Avatar asked Dec 02 '14 19:12

Diosney


People also ask

How do I clear and reinstall npm cache?

Run: “npm cache clean –force” npm cache clean --force or npm cache clean -f . This will force delete the npm cache on your computer.

How do I clean and reinstall node modules?

There are two ways to clean up the node_modules folder: Delete the folder and reinstall. Use npm prune (starting with npm version 6)

Does npm do a clean install?

The npm clean-install command (or npm ci for short) is an in-place replacement for npm install with two major differences: It does a clean install: if the node_modules folder exists, npm deletes it and installs a fresh one. It checks for consistency: if package-lock.


1 Answers

This is precisely what the npm rebuild command does. Just run npm rebuild inside your app directory after it is copied over to the new VM and any binary add-ons will be recompiled to match the current CPU architecture and node version. If the initial npm install before the copy was completely successful, the npm rebuild on the second VM will not need to download anything. Just make sure the second VM has a reasonably-close version of node and the appropriate lower level compilers, libraries, etc (build-essential and python on debian, for example).

like image 88
Peter Lyons Avatar answered Sep 28 '22 16:09

Peter Lyons