How to prevent node-gyp from downloading node-head

2019-03-19 12:32发布

问题:

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?

回答1:

As it suggests here, you can use the --tarball option for node-gyp https://github.com/nodejs/node-gyp/issues/1133