Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 280
Volodymyr Bezuglyy Avatar asked Mar 10 '17 15:03

Volodymyr Bezuglyy


People also ask

Why does node use gyp?

node-gyp is a cross-platform command-line tool written in Node. js for compiling native addon modules for Node. js. It contains a vendored copy of the gyp-next project that was previously used by the Chromium team, extended to support the development of Node.

Which file does node-gyp use to read the configuration?

gyp file describes the configuration to build your module, in a JSON-like format. This file gets placed in the root of your package, alongside package. json .

What is node-gyp folder?

node-gyp folder is the devDir of node-gyp (see relevant source code). This is where development header files are copied in order to perform the compilation of native modules. you can safely delete this directory, as it will be re-created the next time you'll install a module that needs node-gyp .


1 Answers

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 
like image 70
Abhishek Avatar answered Sep 20 '22 14:09

Abhishek