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

22

我正在从一个项目中运行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

当我执行npm list命令时,出现以下消息。

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

抱歉,我对Node.js完全是新手。

6个回答

20

发生这种情况的原因是node-gypnode@0.11.8-pre中的-pre部分评估为-1。然后安装程序收到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

要解决这个问题,请使用Node.js的稳定版本。否则,您需要准备好Node源代码,并使用 --nodedir 标志。

npm install --nodedir=/node/src/

您可以在这里阅读有关此问题的更多信息。


11

我通过将我的 Node 版本升级到稳定版本(例如不是“pre”版本,您的版本是0.8.13-pre)来解决这个问题,具体方法如下:

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

7

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

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


3

我曾经遇到过同样的问题。通过将Node.js版本降级到较旧的版本,问题得以解决。我使用nvm来管理不同版本的Node.js。更多细节可以在这里查看。

nvm list   

    16.10.0
    16.3.0
  * 14.15.0 (Currently using 64-bit executable)

0

在安装node-sass时,我遇到了同样的问题:

通过卸载node-sass,我解决了这个问题:

node uninstall node-sass

然后像这样安装它,它会为您工作:

node install sass --save

0

node-gyp 错误是在 npm 安装期间发生的常见问题,当一个包需要编译本地模块时会出现此错误。这个错误是因为本地模块需要在您的本地机器上编译,但它需要安装某些工具和依赖项。

npm install -g node-gyp


如果这些步骤无法解决问题,您可能需要检查软件包文档以获取任何其他说明或联系软件包维护者获取支持。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接