Search code examples
node.jslinuxnpmnpm-installsoftware-packaging

How to split `npm install` to two steps to perform offline builds?


I am trying to build an application requiring NPM on Open Build Service. When building the application locally, one of the steps is cding into a directory containing package.lock and then running npm install.

For obvious reasons this fails on a computer with no internet access.

What I would like is to download the required node modules somehow and then add them as part of the application source.

If node_modules included only text files, I could just tar it up and unpack it on the remote server. Unfortunately, some of the modules include binaries which are built by NPM using g++, and I don't want to include opaque binaries as a “source”.

How can I split npm install into two steps:

  1. to be performed locally and producing human-readable source
  2. to be performed by OBS using downloaded sources and not requiring internet access?

Solution

  • The first step is npm install --ignore-scripts, the second is npm rebuild.