Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

building native module in windows subsystem for linux #163

Open
srikanthkampati opened this issue Nov 3, 2020 · 2 comments
Open

building native module in windows subsystem for linux #163

srikanthkampati opened this issue Nov 3, 2020 · 2 comments

Comments

@srikanthkampati
Copy link

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 [email protected]
gyp info using [email protected] | 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

@mhdawson
Copy link
Member

mhdawson commented Nov 5, 2020

@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.

@SeanKudrna
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants