本以为安装很简单很顺利
按照官方文档就操作就完了 结果各种错误。
创建您的第一个应用程序 | Electron (electronjs.org)
第一步安装nodejs 这个还是简单
国内可以直接访问官网 nodejs.org
安装完成之后打开命令行工具,输入node -v,npm -v,可以看到如下显示,说明node安装成功。
第二步把示例代码拉下来
然后
npm install
npm start
这两个命令
如果是自己新建的项目 需要运行如下命令
cnpm install --save-dev electron 或则 cnpm install electron
cnpm start
运行下来结果报错 懵逼
错误如下
UnhandledPromiseRejectionWarning: RequestError: read ECONNRESET
index.js:14 throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
原因:国内镜像拉取失败
先删除之前的依赖文件夹node_modules 然后安装淘宝镜像 然后在重新初始
解决办法安装淘宝npm镜像
npm install -g cnpm --registry=registry.npm.taobao.org
检查安装成功
cnpm -v
补充
修改路径
cnpm config set cache "D:\nodejs\node_cache"
cnpm config set prefix "D:\nodejs\node_global"
重新打开代码
运行
cnpm install
发现在vscode中还报错
无法加载文件 C:\Users\WANG\AppData\Roaming\npm\cnpm.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_P
解决办法
1.以管理员身份运行power shell
2.输入set-ExecutionPolicy RemoteSigned
然后输入A 回车
然后在重新
cnpm install
cnpm start
最后终于运行成功
vscode 调试launch.json 文件
{ "version": "0.2.0", "configurations": [ { "name": "Debug Main Process", "type": "node", "request": "launch", "cwd": "${workspaceFolder}", "console": "integratedTerminal", "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron", "windows": { "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd" }, "args" : ["."] } ] }