简体   繁体   中英

Why does electron fail to start?

I have just started working with electron recently, using a tutorial posted here . The github for the project template I created for myself to use based off of what I learned is here . The README of that repo shows all of the things I did when creating that template.

So far everything has been hunky dory, at least for the first couple times I run npm run dev after running npm install and npm run build . After maybe two or three successful attempts, when I return to the project later to try and run it, the concurrency plugin will load wait-on properly, but wait-on never seems to trigger when the react-scripts finishes successfully initiating the local server for the react page. Here is my output:

PS D:\Home\Projects\finally> npm run dev
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> finally@0.1.0 dev
> concurrently -k -s command-electron "cross-env BROWSER=none npm start" "npm:electron"

[electron] npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
[0] npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
[electron]
[electron] > finally@0.1.0 electron
[electron] > wait-on tcp:3000 && electron .
[electron]
[0]
[0] > finally@0.1.0 start
[0] > react-scripts start
[0]
[0] (node:4504) [DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning: 'onAfterSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[0] (Use `node --trace-deprecation ...` to show where the warning was created)
[0] (node:4504) [DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE] DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated. Please use the 'setupMiddlewares' option.
[0] Starting the development server...
[0]
[0] Compiled successfully!
[0]
[0] You can now view finally in the browser.
[0]
[0]   Local:            http://localhost:3000
[0]   On Your Network:  http://172.28.224.1:3000
[0]
[0] Note that the development build is not optimized.
[0] To create a production build, use npm run build.
[0]
[0] webpack compiled successfully
[0] No issues found.

At this point it never continues, it just hangs, and the electron window never populates. I have tried recreating the repo a couple times, deleting build and node_modules and reinstalling, but nothing seems to be a common factor.

Also it should be noted, this is without having added any code beyond what that template provides. I clone the template, try to run it, it works a couple times, and then no more.

Any insights?

This could be caused by node.js update.

This fixes it

  1. Go to the node.js installation folder, eg. C:\Program Files\nodejs
  2. Open npm.cmd with notepad as admin
  3. Edit the file by replacing prefix -g with prefix --location=global , and Save
  4. Make the same change to npx.cmd too

Test if it is fixed

If it is not fixed, try updating npm using npm install npm@latest -g

在此处输入图像描述


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM