pnpm安装electron依赖失败报错的解决方法

今天拉了一个项目,使用 pnpm install 安装依赖时报错:

!❯ pnpm i electron -D       
../../..                                 | +343 ++++++++++++++++++++++++++++++++++
Packages are copied from the content-addressable store to the virtual store.
  Content-addressable store is at: E:\.pnpm-store\v3
  Virtual store is at:             ../../../node_modules/.pnpm
../../..                                 | Progress: resolved 398, reused 355, downloaded 0, added 1, done
../../../node_modules/.pnpm/[email protected]/node_modules/electron: Running postinstall script, failed in 21.5s
.../node_modules/electron postinstall$ node install.js
│ RequestError: connect ETIMEDOUT 20.205.243.166:443
│     at ClientRequest.<anonymous> (E:\.websites\Dtool\node_modules\.pnpm\[email protected]\node_modules\got\dist\source\core\index.js:970:111)
│     at Object.onceWrapper (node:events:510:26)
│     at ClientRequest.emit (node:events:402:35)
│     at ClientRequest.origin.emit (E:\.websites\Dtool\node_modules\.pnpm\@[email protected]\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
│     at TLSSocket.socketErrorListener (node:_http_client:447:9)
│     at TLSSocket.emit (node:events:390:28)
│     at emitErrorNT (node:internal/streams/destroy:157:8)
│     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
│     at processTicksAndRejections (node:internal/process/task_queues:83:21)
│     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
└─ Failed in 21.5s at E:\.websites\Dtool\node_modules\.pnpm\[email protected]\node_modules\electron
 ELIFECYCLE  Command failed with exit code 1.

可以看出是安装 electron 依赖失败,大概率是网络原因,导致无法正常下载,设置一下 pnpm 的源为 taobao 的 electron 源:

pnpm

pnpm config set electron_mirror "https://npm.taobao.org/mirrors/electron/"

npm

npm config set electron_mirror "https://npm.taobao.org/mirrors/electron/"

再安装就可以了:

!❯ pnpm i electron -D
../../..                                 | +343 ++++++++++++++++++++++++++++++++++
../../..                                 | Progress: resolved 398, reused 355, downloaded 0, added 0, done
../../../node_modules/.pnpm/[email protected]/node_modules/electron: Running postinstall script, done in 18.5s
Done in 22.6s


未经允许不得转载:前端资源网 - w3h5 » pnpm安装electron依赖失败报错的解决方法

赞 (0)
分享到: +

评论 沙发

Avatar

换个身份

  • 昵称 (必填)
  • 邮箱 (选填)