今天拉了一个项目,使用 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-storev3
Virtual store is at: ../../../node_modules/.pnpm
../../.. | Progress: resolved 398, reused 355, downloaded 0, added 1, done
../../../node_modules/.pnpm/electron@26.1.0/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:.websitesDtoolnode_modules.pnpmgot@11.8.6node_modulesgotdistsourcecoreindex.js:970:111)
│ at object.onceWrapper (node:events:510:26)
│ at ClientRequest.emit (node:events:402:35)
│ at ClientRequest.origin.emit (E:.websitesDtoolnode_modules.pnpm@szmarczak http-timer@4.0.6node_modules@szmarczakhttp-timerdistsourceindex.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:.websitesDtoolnode_modules.pnpmelectron@26.1.0node_moduleselectron
ELIFECYCLE Command failed with exit code 1.
可以看出是安装 electron 依赖失败,大概率是网络原因,导致无法正常下载,设置一下 pnpm 的源为 taobao 的 electron 源:
pnpm
代码语言:javascript复制pnpm config set electron_mirror "https://npm.taobao.org/mirrors/electron/"
npm
代码语言:javascript复制npm config set electron_mirror "HTTPS://npm.taobao.org/mirrors/electron/"
再安装就可以了:
代码语言:javascript复制!❯ pnpm i electron -D
../../.. | 343
../../.. | Progress: resolved 398, reused 355, downloaded 0, added 0, done
../../../node_modules/.pnpm/electron@26.1.0/node_modules/electron: Running postinstall script, done in 18.5s
Done in 22.6s
未经允许不得转载:Web前端开发资源网 » pnpm安装electron依赖失败报错的解决方法