解决windows上electron运行报错的解决
今天折腾electron,按照官网说明一步步做下来然后npm start却报错:
> electron . C:\Users\xxx\AppData\Roaming\npm\node_modules\electron\index.js:14 throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again') ^ Error: Electron failed to install correctly, please delete node_modules/electron and try installing again at getElectronPath (C:\Users\xxx\AppData\Roaming\npm\node_modules\electron\index.js:14:11) at Object.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\electron\index.js:18:18) at Module._compile (internal/modules/cjs/loader.js:955:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10) at Module.load (internal/modules/cjs/loader.js:811:32) at Function.Module._load (internal/modules/cjs/loader.js:723:14) at Module.require (internal/modules/cjs/loader.js:848:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\electron\cli.js:3:16) at Module._compile (internal/modules/cjs/loader.js:955:30) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! xxx@1.0.0 start: `electron .` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the xxx@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\xxx\AppData\Roaming\npm-cache\_logs\2020-01-15T07_52_20_936Z-debug.log
网上各种叫人删掉node_modules/electron改成淘宝源的操作做过了,都没有效果。最后自己折腾出来了。
1、到 https://github.com/electron/electron/releases/ 下载对应版本的electron(例如我下载的是electron-v7.1.9-win32-x64.zip);
2、解压缩到node_modules/electron/dist/目录里;
3、在node_modules/electron/里创建一个叫path.txt的文件里面,在里面写上electron.exe保存。
再npm start就成功了,真坑。