How to prevent node-gyp from downloading node-headers.tar.gz and node.lib from internet?

Volodymyr Bezuglyy picture Volodymyr Bezuglyy · Mar 10, 2017 · Viewed 12.7k times · Source

node-gyp downloads following files from the Internet during installation and building of the native modules like iconv, ref, ffi, etc:
https://nodejs.org/download/release/v6.10.0/node-v6.10.0-headers.tar.gz
https://nodejs.org/download/release/v6.10.0/win-x86/node.lib
https://nodejs.org/download/release/v6.10.0/win-x64/node.lib
https://nodejs.org/download/release/v6.10.0/SHASUMS256.txt

How to make node-gyp to use these files from local folders, not from the Internet?

I've found the following solution:
1. Download https://nodejs.org/download/release/v6.10.0/node-v6.10.0-headers.tar.gz
2. Unpack it to some local folder.
3. Create folder Release in this local folder.
4. Download file https://nodejs.org/dist/v6.10.0/win-x64/node.lib into the folder Release.
5. Set property nodedir in .npmrc which will point to the folder with unpacked headers:
nodedir=D:\tools\node_src\node-v6.10.0-headers

Now npm installs packages and node-gyp builds native packages without downloading node headers and libs from the Internet.
Is it a correct approach?

I cannot find in the documentation that I should download node.lib and put it to the Release directory.
I decided to do it after analyzing the traces of node-gyp and code of node-gyp.
Is it possible to setup the location of node.lib using some npm_config_xxx property?

Answer

Abhishek picture Abhishek · Sep 24, 2020

Below works for me:

# download for private repo, probably you're behind firewall
curl -k -o node-v8.9.4-headers.tar.gz -L https://nexus.com/repository/binaries/node/v8.9.4/node-v8.9.4-headers.tar.gz

# capture the absolute path
TARBALL_PATH=$(pwd)

# configure tarball in npm config
npm config set tarball ${TARBALL_PATH}/node-v8.9.4-headers.tar.gz

# The below command should pass without gyp error
npm install