在进行npm安装时出现node-gyp错误

时间:2013-09-13 03:35:43

标签: node.js pty

我正在从一个项目进行npm安装,我在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

当我执行npm列表时,我收到以下消息。

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

抱歉,我是nodejs的新手。

3 个答案:

答案 0 :(得分:15)

发生这种情况的原因是node-gyp-pre的{​​{1}}部分评估为node@0.11.8-pre。然后,安装会收到-1并失败。

404

要解决此问题,请使用Node.js的稳定版本。否则,您需要放置节点源,并使用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 标志。

--nodedir

您可以详细了解此问题here

答案 1 :(得分:5)

我通过将我的节点版本升级到稳定版本(例如,不是“预”版本 - 您的版本是0.8.13-pre)来解决这个问题,并使用以下内容:

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

答案 2 :(得分:0)

我在安装 node-sasswindows-build-tools 时遇到了同样的问题。我使用的是 node-v16.2.0,所以它不是任何 -pre 版本。我也更新到了最新版本 (node-v16.3.0),但也没有解决我的问题。

最后,我通过卸载现有版本并安装 LTS 版本(发布时为 v14.17.0)解决了这个问题。