节点 10 - npm 安装过程中出现“node-gyp 重建”错误

Dav*_*aiz 12 node.js node-gyp

我最近升级到 Node 10,运行时npm install出现以下错误:

make: *** [Release/obj.target/memwatch/src/init.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/david/Documents/gitlab/project/node_modules/memwatch-next
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! memwatch-next@0.3.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the memwatch-next@0.3.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

在“macOS Mojave”上工作,我使用 Node10 在同一个项目上工作,没有任何问题。请告知可能导致错误的原因?

Dav*_*aiz 6

通过将 npm 更新到最新版本并运行 npm rebuild 解决了该问题。


moh*_*adi 5

我认为删除这个目录更好:

rm -rf ~/.node-gyp/
rm -r node_modules/.bin/;
rm -r build/
Run Code Online (Sandbox Code Playgroud)

你可以测试

npm install -g node-gyp
Run Code Online (Sandbox Code Playgroud)

npm install -g node-pre-gyp
Run Code Online (Sandbox Code Playgroud)

最后:

npm install <your module>
Run Code Online (Sandbox Code Playgroud)