节点 10 - npm 安装期间出现“node-gyp rebuild”错误

Node 10 - `node-gyp rebuild` error during npm install

我最近升级到 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.

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

不知道实际的 node-gyp 错误,请确保您已经为您的平台安装了 node-gyp dependencies

通过将 npm 更新到最新版本和 运行 npm rebuild 解决了这个问题。

我遇到了同样的问题,解决方法是 删除 yarn.lock 文件,然后 运行 再次删除 yarn install

我觉得删除这个目录比较好:

rm -rf ~/.node-gyp/
rm -r node_modules/.bin/;
rm -r build/

你可以测试

npm install -g node-gyp

npm install -g node-pre-gyp

终于:

npm install <your module>

我遇到了同样的问题。首先我删除了 package.json 和 运行 npm install 但它没有帮助。 只有 return 到以前的稳定节点版本对我有帮助。 (nvm 很有用)

使用NVM管理节点。这真的很有帮助。我有同样的错误,但通过使用最新的 Node LTS 版本解决了它。这可以通过一个命令轻松地使用 NVM 完成。

nvm install --lts