WSL2 节点:npm install cpu-features -> npm ERR! /bin/sh: 1: cmake: 权限被拒绝
Posted
技术标签:
【中文标题】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 【发布时间】:2021-09-23 06:52:22 【问题描述】:我有一个运行良好的反应项目。 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 用户身份运行。
我想知道为什么我会收到拒绝授权的错误消息。文件和文件夹不是 root 用户/组。
【问题讨论】:
试试sudo npm install cpu-features
@Mikhail 它只是挂起,也没有使用与 nvm 一起安装的 npm,而是使用 sudo apt install npm
安装的 npm,它是旧版本(npm@6.14.4)。当我在没有 sudo
的情况下运行时,它使用的是 v7.19.1 的 /home/ilkkae/.nvm/versions/node/v14.17.0
【参考方案1】:
确保您已经在 Linux 中安装了cmake
模块。它不会随 build-essentials 一起安装。这就是我摆脱同样错误的方法。
sudo apt-get install cmake
【讨论】:
【参考方案2】:除了@Artoiss的回答,如果你是和我一样被这个问题困扰的Mac用户,你可以使用Brew轻松安装;
brew install cmake
如果您尚未在 Mac 中安装 Brew,请查看此处Home Brew - Installation
【讨论】:
【参考方案3】:cpu-features 根据他们的 (npm) 文档需要 CMake:https://www.npmjs.com/package/cpu-features#requirements
这可以通过多种方式在本地安装。以 mac 为例:
brew install cmake
【讨论】:
以上是关于WSL2 节点:npm install cpu-features -> npm ERR! /bin/sh: 1: cmake: 权限被拒绝的主要内容,如果未能解决你的问题,请参考以下文章
NVM:npm install -g 一直使用错误的节点版本