使用electron的demo时的错误
Electron | Build cross-platform desktop apps with JavaScript, HTML, and CSS. (electronjs.org)
环境基本的配置,node.js,git啥的都搞好,都是最新版的,然后就是下面三步
$ git clone https://github.com/electron/electron-quick-start
$ cd electron-quick-start
$ npm install && npm start
使用git clone的时候下载不下来
error: RPC failed; curl 28 OpenSSL SSL_read: Connection was reset, errno 10054
那就先执行
git init
再输入:
git config http.sslVerify "false"
然后再clone就行了
要是还不行,就镜像
npm config set registry https://registry.npm.taobao.org
or
npm install -g cnpm --registry=https://registry.npm.taobao.org
一般这样就可以了
在对应目录中npm install && npm start错误
最开始是出现
Electron failed to install correctly, please delete node_modules/electron and try installing again
然后在下面的报错中看到了
Not Found - GET https://registry.npm.taobao.org/@types/node/-/node-14.17.9.t
所以又把镜像换了回去
这个报错是消失了,但是换回去以后,出了新的报错
内容如下:
npm ERR! code 1
npm ERR! path E:DAIMAelectron-quick-start
ode_moduleselectron
npm ERR! command failed
npm ERR! command C:Windowssystem32cmd.exe /d /s /c node install.js
npm ERR! RequestError: read ECONNRESET
npm ERR! at ClientRequest.<anonymous> (E:DAIMAelectron-quick-start
ode_modulesgotsource
equest-as-event-emitter.js:178:14)
npm ERR! at Object.onceWrapper (node:events:514:26)
npm ERR! at ClientRequest.emit (node:events:406:35)
npm ERR! at ClientRequest.origin.emit (E:DAIMAelectron-quick-start
ode_modules@szmarczakhttp-timersourceindex.js:37:11)
npm ERR! at TLSSocket.socketErrorListener (node:_http_client:447:9)
npm ERR! at TLSSocket.emit (node:events:394: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)
找到关键的 RequestError: read ECONNRESET,发现是卡在install.js不动了,用了很多方法都不行
然后找到了一个解决electron安装,卡在install.js不动的问题,UnhandledPromiseRejectionWarning: RequestError: read ECONNRESET_Miuanan-CSDN博客,直接解决了这个问题
因为我是直接下的官网的demo,所以步骤有点不同,就记录一下
ctrl+win 输入cmd,cd到项目文件夹,输入
npm init
初始化项目以后一路回车,然后再输入
npm install electron --save-dev
然后再输入
npm --registry=https://registry.npm.taobao.org install
然后放着先不管,直接下载的https://cdn.npm.taobao.org/dist/electron/7.0.0/electron-v7.0.0-win32-x64.zip并复制到
项目存放位置electron-quick-start
ode_moduleselectron
重命名为electron.zip
然后修改项目存放位置electron-quick-start ode_moduleselectroninstall.js,内容如下:
#!/usr/bin/env node
const version = require('./package').version
const fs = require('fs')
const os = require('os')
const path = require('path')
const extract = require('extract-zip')
const platformPath = 'electron.exe'
const zipPath = "./electron.zip"
extractFile (zipPath)
// unzips and makes path.txt point at the correct executable
function extractFile (zipPath) {
extract(zipPath, { dir: path.join(__dirname, 'dist') }, function (err) {
if (err) return onerror(err)
fs.writeFile(path.join(__dirname, 'path.txt'), platformPath, function (err) {
if (err) return onerror(err)
})
})
}
然后直接在在命令行输入npm start
等待一下即可启动
如果老是出现卡在app.后面的字符的情况,像是app.whenReady(),就会卡在w这里,这种情况,就不要用nodemon,直接普通的启动就可以了