npm install jest出错

来源:3-9 介绍jest-基本使用

慕设计9348276

2021-02-27

请教老师,不知道为什么我的node环境突然出了问题,用npm install jest总是出错,弹出一堆错误,网上找了许久也没有解决,重装了node,和node-gyp也不行,错误信息如下:

npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@14.16.0 | win32 | x64
npm ERR! gyp info find Python using Python version 3.7.4 found at "C:\Users\XXX\AppData\Local\Programs\Python\Python37\python.exe"
npm ERR! gyp http GET https://nodejs.org/download/release/v14.16.0/node-v14.16.0-headers.tar.gz
npm ERR! gyp WARN install got an error, rolling back install
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: connect ETIMEDOUT 104.20.22.46:443
npm ERR! gyp ERR! stack at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
npm ERR! gyp ERR! System Windows_NT 10.0.18363
npm ERR! gyp ERR! command “C:\Program Files\nodejs\node.exe” “C:\Users\XXXX\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js” "rebuild"
npm ERR! gyp ERR! cwd D:\XXXX\node_modules\bufferutil
npm ERR! gyp ERR! node -v v14.16.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

看提示,好像是去nodejs官网里下载源码时连接出错,node-gyp需要重新编译源码,我也下载了源码了,并在源码解压的目录下去执行了node-gyp install也是不行,不知道怎么解决好,我也不明白为什么安装一个插件就需要用到node-gyp去编译源码的,老师可以帮忙看看吗? 谢谢

写回答

2回答

Emmy_M

2021-03-11

我遇到了同样的问题, 安装了跟老师一样的版本解决了. `npm i jest@24.9.0 -D`

1
1
Narmo
+1同问题
2021-07-21
共1条回复

双越

2021-02-27

使用淘宝代理试试

npm i jest --save-dev --registry=https://registry.npm.taobao.org

0
4
慕设计9348276
回复
双越
谢谢老师
2021-02-28
共4条回复

Node.js+Koa2框架生态实战 - 从零模拟新浪微博

用 Koa2 做真正的实战项目,不再只是增删改查的小白工程师

964 学习 · 388 问题

查看课程