简体   繁体   English

执行 npm install 时出现 node-gyp 错误

[英]node-gyp error while doing npm install

I am doing npm install from a project and I am getting this wierd error in node-gyp.我正在从一个项目中进行 npm install 并且我在 node-gyp 中遇到了这个奇怪的错误。

> pty.js@0.2.3 install /home/charizard/Open/terminal-codelearn/node_modules/pty.js
> node-gyp rebuild

npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/tinycolor
npm http GET https://registry.npmjs.org/options
gyp ERR! configure error 
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack     at install (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:65:16)
gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:66:37)
gyp ERR! stack     at getNodeDir (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:228:20)
gyp ERR! stack     at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:110:9
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:659:7)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:106:17)
gyp ERR! stack     at maybeClose (child_process.js:773:16)
gyp ERR! stack     at Socket.<anonymous> (child_process.js:986:11)
gyp ERR! stack     at Socket.EventEmitter.emit (events.js:103:17)
gyp ERR! stack     at Pipe.close (net.js:458:12)
gyp ERR! System Linux 3.5.0-37-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/charizard/Open/terminal-codelearn/node_modules/pty.js
gyp ERR! node -v v0.11.8-pre
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok 
npm ERR! weird error 1

When I do npm list, I get this following message.当我执行 npm list 时,我收到以下消息。

npm ERR! missing: pty.js@>=0.2.2, required by terminal-codelearn@0.0.3
npm ERR! not ok code 0

Sorry, I am completely new to nodejs.抱歉,我对 nodejs 完全陌生。

The reason this happens is that node-gyp evaluates the -pre part of node@0.11.8-pre as -1 .发生这种情况的原因是node-gyp node@0.11.8-pre-pre部分评估为-1 The install then receives a 404 and fails.然后安装会收到404并失败。

gyp http GET http://nodejs.org/dist/v0.8.-1/node-v11.8.-1.tar.gz
gyp http 404 http://nodejs.org/dist/v0.8.-1/node-v11.8.-1.tar.gz

To solve this problem, use a stable release of Node.js.要解决此问题,请使用稳定版本的 Node.js。 Otherwise, you need to have the Node source lying around, and use the --nodedir flag.否则,您需要--nodedir Node 源,并使用--nodedir标志。

npm install --nodedir=/node/src/

You can read more about this issue here .您可以在此处阅读有关此问题的更多信息。

I solved this by upgrading my version of node to a stable version (eg not a "pre" version - your version is 0.8.13-pre) with the following:我通过将我的节点版本升级到稳定版本(例如不是“预”版本 - 您的版本是 0.8.13-pre)解决了这个问题:

sudo npm install -g n # install node version manager "n"
sudo n stable # install the latest stable version of node

I faced the same problem while installing node-sass as well as windows-build-tools .我在安装node-sasswindows-build-tools遇到了同样的问题。 I was using node-v16.2.0 , so it wasn't any -pre release.我使用的是node-v16.2.0 ,所以它不是任何-pre版本。 I also updated to the latest version ( node-v16.3.0 ) but it did not solve my issue either.我也更新到最新版本( node-v16.3.0 ),但它也没有解决我的问题。

Finally, I solved it by uninstalling the existing version and installing the LTS version ( v14.17.0 at the time of posting).最后,我通过卸载现有版本并安装LTS版本(发布时为v14.17.0 )来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM