Open srikanthkampati opened 3 years ago
@srikanthkampati I'm not sure this is the right repository for your question. I'm thinking it should be in the help repo instead. Do you mind if I move it there as its more like to get some visibility there.
To enable WSL (Windows Subsystem for Linux) to compile and build native Windows modules with npm install, you'll need to configure your environment to handle the cross-compilation. The error you're encountering with 'gyp' failing at NodeGyp.rebuildModule typically indicates issues with building native addons, which are often C++ modules that need to be compiled for the target platform.
Here are the steps you can take to configure your WSL environment:
Install Windows Build Tools: You need to install the Windows build tools which include the necessary compilers and other tools. This can be done on your Windows system, outside of WSL. Run PowerShell as Administrator and execute:
Install Node.js on Windows:
npm install --global windows-build-tools
Ensure that Node.js is installed on your Windows environment. This is because the native modules you are trying to compile are for Windows, not Linux.
Configure npm to use Windows Node.js from WSL:
Inside WSL, configure npm to use the Windows version of Node.js for building. You can do this by setting the npm_config_node_gyp environment variable to point to the node-gyp binary in your Windows Node.js installation. Add the following line to your .bashrc
or .zshrc
file in WSL:
export npm_config_node_gyp=/mnt/c/path/to/nodejs/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js
Replace/path/to/nodejs
with the actual path to your Node.js installation on the Windows file system.
Typically, it would be in Program Files.
Make sure you can access the Windows file system from WSL. You should be able to navigate to your Windows file system using /mnt/c/
in the WSL terminal.
Run npm Install:
Now, try running npm install
from within your project directory in WSL. It should use the Windows-native tools to compile the modules.
below is the error i am getting when i am trying to build a native .node file in WSL. gyp info it worked if it ends with ok gyp info using node-gyp@7.1.2 gyp info using node@8.10.0 | linux | x64 gyp info find Python using Python version 3.6.7 found at "/usr/bin/python3" gyp WARN install got an error, rolling back install gyp ERR! configure error gyp ERR! stack Error: ENOENT: no such file or directory, mkdir '/root/.cache/node-gyp/8.10.0' gyp ERR! System Linux 4.4.0-17763-Microsoft gyp ERR! command "/usr/bin/node" "/usr/local/bin/node-gyp" "rebuild" gyp ERR! cwd /mnt/d/workspace/NAS_EDIE/Tool_Libraries/node-examples/1_hello_world gyp ERR! node -v v8.10.0 gyp ERR! node-gyp -v v7.1.2 gyp ERR! not ok