Cannot start Electron application - missing packag

2019-08-10 05:25发布

问题:

I'm currently doing a Python project where I want to display my results in an Electron application. I have seen a demo video on YouTube on how to set up Electron on a Mac. The video showed 3 simple steps to be executed in the terminal:

git clone https://github.com/electron/electron-quick-start
cd electron-quick-start
npm install && npm start

When I first ran the above commands it worked fine for me. I was able to start the Electron application.

But when I tried to re-start the application using the command npm start after going into the electron-quick-start directory, I am not able to open the application.

I am continuously getting an error message as follows:

(base) Viveks-MacBook-Pro:electron-quick-start vivekchowdary$ npm start
npm ERR! path /Users/vivekchowdary/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/Users/vivekchowdary/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/vivekchowdary/.npm/_logs/2019-04-19T12_55_01_157Z-debug.log
(base) Viveks-MacBook-Pro:electron-quick-start vivekchowdary$ 

I don't know what it means? But I just want to open the Electron application.

回答1:

As the error message states, the file package.json cannot be found.

One possible reason is that the terminal is not in the correct project folder and that you need to cd into the folder before running npm start.

If you cd to any folder that has no package.json (and whose parent folders don't have a package.json) and run npm start, you'll be presented with this error message.

Your specific file path seems to indicate that you ran npm start from your home folder, not the project folder that contains package.json.