Nodejs / npm:如何重新安装/重新编译复制的应用程序包

时间:2020-12-26 17:43:12

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.

    具有Internet连接的VM,其中将执行npm install以安装所有应用程序依赖项。结果将是app及其在node_modules中的依赖项的文件夹。

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

    应用程序模块之间是fi:mongoose,在安装时使用node-gyp编译本机BSON扩展。

  • 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.

    app文件夹被复制到另一个没有Internet连接的VM,它完全正常运行,但编译后的扩展不起作用,但它的.js后备功能。

Question:

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

如何在没有Internet连接的情况下重新安装/重新编译/重新生成新VM上的所有应用程序模块?

1 个解决方案

#1


12  

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).

这正是npm rebuild命令所做的。在将应用程序目录复制到新VM后,只需在应用程序目录中运行npm rebuild,将重新编译任何二进制加载项以匹配当前的CPU体系结构和节点版本。如果复制之前的初始npm安装完全成功,则第二个VM上的npm rebuild将不需要下载任何内容。只需确保第二个VM具有合​​理关闭的节点版本和适当的低级编译器,库等(例如,build-essential和python on debian)。

#1


12  

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).

这正是npm rebuild命令所做的。在将应用程序目录复制到新VM后,只需在应用程序目录中运行npm rebuild,将重新编译任何二进制加载项以匹配当前的CPU体系结构和节点版本。如果复制之前的初始npm安装完全成功,则第二个VM上的npm rebuild将不需要下载任何内容。只需确保第二个VM具有合​​理关闭的节点版本和适当的低级编译器,库等(例如,build-essential和python on debian)。