错误描述:

在安装 electron 的时候,使用官方推荐的如下命令:

npm install --save-dev electron

结果报错如下

在这里插入图片描述

npm ERR! code 1
npm ERR! path D:\AWQW\electron\demo-test\node_modules\electron
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node install.js
npm ERR! RequestError: connect ETIMEDOUT 39.102.194.95:443
npm ERR!     at ClientRequest.<anonymous> (D:\AWQW\electron\demo-test\node_modules\got\dist\source\core\index.js:970:111)
npm ERR!     at Object.onceWrapper (node:events:510:26)
npm ERR!     at ClientRequest.emit (node:events:402:35)
npm ERR!     at ClientRequest.origin.emit (D:\AWQW\electron\demo-test\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:447:9)
npm ERR!     at TLSSocket.emit (node:events:390:28)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:157:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:122:3)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR!     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1146:16)

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2022-12-21T08_31_06_218Z-debug-0.log

分析:

  • 首先考虑是否是由于要下载的东西在国外,导致的下载失败,所以开启了翻墙软件,依旧无效,下载很快,在下载完成的时候,node_modules 包自动删除并开始报错。
  • 其次考虑是否是 node 与 npm 版本不一致导致的,所以更新了 npm 的版本,结果依旧无效。
  • 无中文路径

解决:

使用 cnpm 进行安装

cnpm i electron --save-d

在这里插入图片描述

成功安装!!!


PS:cnpm 的安装方法

npm install -g cnpm --registry=https://registry.npm.taobao.org

推荐这种方式安装是因为既不会影响npm命令,又不用每次都写淘宝地址进行依赖包的安装

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐