I recently started using electron. I have successfully completed the 1st phase by creating a hello world app (included files index.html, main.js, package.json). Now I am trying to package the app using electron-packager but getting this error
Steps I have followed:
- Created a project directory named helloworld.
- Initialized the project directory using
npm init
command. - Then installed electron using
npm install electron --save-dev
. - Then created the javascript and html files as main.js and index.html respectively.
- Then used
npm start
to execute the application. - Then installed electron-packager using
npm install electron-packager
. - Now the problem is coming in this step when i am trying to pacakge the app using command
electron-packager .
I might be totally off with it but my fix was that I put the dot without space just make sure in you package.json file its "start": "electron ." Fixed it for me at least
If you have installed it locally with:
Then, it's not gonna work, install it globally as a cli:
You can also get it through:
After All, if you don't get it working, install electron-packager. Then, go to your package.json. And beneath your start scripts. Make another string named "build" and give it a value of the electron-packager command you want to run:
Then, go in command prompt or terminal or bash. Then, type:
You've to install electron-packager globally, that's why it shows
'electron-packager' is not recognized as an internal or external command
For this, you have to install electron-package globally
You can install globally by using -g option.
Example:-
npm install -g electron-packager
ORnpm i -g electron-packager
//i stands for installPerform a global package install:
The
-g
flag tells NPM to install the package globally which makes the commandelectron-packager
available in your PATH.If you don't want to do a global install you can install it locally and run with
npx
.Alternatively, you can reference it straight from the node_modules folder (not recommended).
There are two cases to make it work...
as discussed above, install electron globally using -g, i.e. using npm install -g electron-packager
change in your package.json, "scripts": { "start": "electron-packager ." }, and then give command npm start.
This way it worked for me..