WSL2 节点:npm install cpu-features -> npm ERR! /bin/sh: 1: cmake: 权限被拒绝

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

我有一个运行良好的 React 项目。 node (v14.17.0) 和 npm (7.19.1) 随 nvm.

安装

使用 npm 安装包很好,例如对于 ssh2 但在安装它时,它不会安装可选包 cpu-features https://github.com/mscdex/cpu-features

当 运行 npm install cpu-features 我得到错误 npm ERR! /bin/sh: 1: cmake: Permission denied

整个错误信息:

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

我已经尝试将所有文​​件传输到 wsl 端,而不是 mnt 文件夹,运行 sudo 这会导致 npm 安装挂起,无论如何都不推荐。

我也试过 运行 作为 root 用户。

我想知道为什么我会收到权限被拒绝的错误消息。文件和文件夹不是根 user/group.

确保您已经在 Linux 中安装了 cmake 模块。它不会与构建要素一起安装。这就是我摆脱同样错误的方法。

sudo apt-get install cmake

除了@Artoiss 的回答,如果你是一个 Mac 用户,和我一样被这个问题困扰,你可以使用 Brew 轻松安装它;

brew install cmake

如果您还没有在 Mac 中安装 Brew,请查看此处 Home Brew - Installation

cpu-features 根据他们的 (npm) 文档需要 CMake:https://www.npmjs.com/package/cpu-features#requirements

这可以通过多种方式在本地安装。例如 mac:

brew install cmake