nklayman / vue-cli-plugin-electron-builder

Easily Build Your Vue.js App For Desktop With Electron
https://nklayman.github.io/vue-cli-plugin-electron-builder/
MIT License
4.12k stars 280 forks source link

Electron failed to install correctly, please delete node_modules/electron and try installing again #1394

Closed xb284524239 closed 3 years ago

xb284524239 commented 3 years ago

Describe the bug When i typed command in the terminal:npm run electron:serve then : Error: Electron failed to install correctly, please delete node_modules/electron and try installing again. I have deleted "node_modules/electron" and tried npm install & npm run electron:serve , it report the same error message again.

To Reproduce node version: 14.16.1 npm version: 7.14.0 vue-cli version: @vue/cli 4.5.13

Steps : 1、vue create helloworld 2、vue add electron-builder 3、npm installl 4、npm run electron:serve 5、report the error message like above

Environment (please complete the following information):

Terminal report:

MacBook-Pro:WorkSpace_VSCode paul$ vue create electron4

Vue CLI v4.5.13 ? Please pick a preset: preference-vue3 ([Vue 3] dart-sass, babel, router, vuex, eslint)

Vue CLI v4.5.13 ✨ Creating project in /Users/paul/Documents/WorkSpace_VSCode/electron4. 🗃 Initializing git repository... ⚙️ Installing CLI plugins. This might take a while...

added 1275 packages in 28s 🚀 Invoking generators... 📦 Installing additional dependencies...

added 92 packages, and changed 1 package in 5s ⚓ Running completion hooks...

📄 Generating README.md...

🎉 Successfully created project electron4. 👉 Get started with the following commands:

$ cd electron4 $ npm run serve

MacBook-Pro:WorkSpace_VSCode paul$ cd electron4 MacBook-Pro:electron4 paul$ vue add electron-builder

📦 Installing vue-cli-plugin-electron-builder...

added 276 packages, and changed 1 package in 9s ✔ Successfully installed plugin: vue-cli-plugin-electron-builder

? Choose Electron Version ^12.0.0

🚀 Invoking generator for vue-cli-plugin-electron-builder... 📦 Installing additional dependencies...

electron4@0.1.0 postinstall electron-builder install-app-deps

• electron-builder version=22.10.5

added 41 packages in 5s ⠋ Running completion hooks...

WARN It is detected that you are using Vue Router. It must function in hash mode to work in Electron. Learn more at https://goo.gl/GM1xZG . ⚓ Running completion hooks...

✔ Successfully invoked generator for plugin: vue-cli-plugin-electron-builder MacBook-Pro:electron4 paul$ npm run electron:serve

electron4@0.1.0 electron:serve vue-cli-service electron:serve

/Users/paul/Documents/WorkSpace_VSCode/electron4/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 (/Users/paul/Documents/WorkSpace_VSCode/electron4/node_modules/electron/index.js:14:11) at Object. (/Users/paul/Documents/WorkSpace_VSCode/electron4/node_modules/electron/index.js:18:18) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Module.require (internal/modules/cjs/loader.js:952:19) at require (internal/modules/cjs/helpers.js:88:18) at Object. (/Users/paul/Documents/WorkSpace_VSCode/electron4/node_modules/vue-cli-plugin-electron-builder/lib/testWithSpectron.js:2:22) at Module._compile (internal/modules/cjs/loader.js:1063:30)

nklayman commented 3 years ago

My guess is that the cached electron download got corrupted. Try deleting your ~/Library/Caches/electron/ folder and node_modules, then reinstall deps.

skythomp16 commented 3 years ago

You can fix this by running the following command: node node_modules/electron/install.js

That is supposed to get fixed when you run npm install but sometimes it doesn't for some reason.