尝试了npm安装-g truffle,但得到这个gyp错误



我尝试了npm节点gyp-g,但没有帮助。我正试着在我的mac上安装块菌。我使用的是macosCatalina,节点版本16.13.1和npm版本8.1.2

npm ERR! code 1
npm ERR! path /usr/local/lib/node_modules/truffle/node_modules/ganache/node_modules/leveldown
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/leveldb/deps/leveldb/leveldb-1.20/db/builder.o
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@8.3.0
npm ERR! gyp info using node@16.13.1 | darwin | x64
npm ERR! gyp info find Python using Python version 3.8.1 found at "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3"
npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/usr/local/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   '/usr/local/lib/node_modules/truffle/node_modules/ganache/node_modules/leveldown/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-/c++/v1/string:505:
...
npm ERR! gyp ERR! System Darwin 19.6.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /usr/local/lib/node_modules/truffle/node_modules/ganache/node_modules/leveldown
npm ERR! gyp ERR! node -v v16.13.1
npm ERR! gyp ERR! node-gyp -v v8.3.0
npm ERR! gyp ERR! not ok

请参阅https://github.com/trufflesuite/truffle/issues/4692,所以为了解决问题,我们必须…

对于非nvm

# Install npm 6
npm i -g npm@6
# Make sure should get npm `6.14.15`
npm --version
# Should work now
npm i -g truffle

对于nvm

# In case you have 16 installed (you can skip this)
npm config delete prefix
# Get npm 6.14.16 from node 14 (or you can try install only npm)
nvm use 14
# Make sure should get npm `6.14.15`
npm --version
# Should work now
npm i -g truffle

以上答案对我不起作用

试试这个:

sudo npm install -g truffle --unsafe-perm

来源:https://github.com/nodejs/node-gyp/issues/2631

最新更新