WSL2 Node: npm install cpu-features -> npm ERR! /bin/sh: 1: cmake: Permission denied

Viewed 3633

I have a react project that works fine. node (v14.17.0) and npm (7.19.1) is installed with nvm.

Installing packages with npm is fine e.g. for ssh2 but installing it, it does not install optional package cpu-features https://github.com/mscdex/cpu-features

When running npm install cpu-features i get error npm ERR! /bin/sh: 1: cmake: Permission denied

Whole error message:

npm ERR! code 1
npm ERR! path /mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! make: Entering directory '/mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features/build'
npm ERR!   ACTION Configuring dependencies /mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features/deps/cpu_features/build/Makefile
npm ERR! make: Leaving directory '/mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@14.17.0 | linux | x64
npm ERR! gyp info find Python using Python version 3.8.5 found at "/usr/bin/python3"
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/home/ilkkae/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/ilkkae/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/ilkkae/.cache/node-gyp/14.17.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/home/ilkkae/.cache/node-gyp/14.17.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/home/ilkkae/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/ilkkae/.cache/node-gyp/14.17.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! make: Warning: File 'cpufeatures.target.mk' has modification time 0.11 s in the future
npm ERR! /bin/sh: 1: cmake: Permission denied
npm ERR! make: *** [config_deps.target.mk:13: /mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features/deps/cpu_features/build/Makefile] Error 127
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/home/ilkkae/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:376:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Linux 5.4.72-microsoft-standard-WSL2
npm ERR! gyp ERR! command "/home/ilkkae/.nvm/versions/node/v14.17.0/bin/node" "/home/ilkkae/.nvm/versions/node/v14.17.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /mnt/c/Users/ilkka/Projects/draganddrop/node_modules/cpu-features
npm ERR! gyp ERR! node -v v14.17.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

I have tried to transfer all files to wsl side so not mnt folder, running with sudo and it causes the npm install to hang and is not recommended anyways.

I also tried running as root user.

I am wondering why do I get premission denied error message. The files and folders are not root user/group.

3 Answers

Make sure that you have installed cmake module in the Linux. It won't not get installed with build-essentials. This is how I got rid of the same error.

sudo apt-get install cmake

In addition to @Artoiss's answer, if you are a Mac user who suffers with this problem just like me, you can easily install it using Brew;

brew install cmake

If you don't have Brew installed in your Mac yet, have a look to here Home Brew - Installation

Related