'electron-packager' is not recognized as an internal or external command
Asked Answered
N

6

20

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

electron-packager error

Steps I have followed:

  1. Created a project directory named helloworld.
  2. Initialized the project directory using npm init command.
  3. Then installed electron using npm install electron --save-dev.
  4. Then created the javascript and html files as main.js and index.html respectively.
  5. Then used npm start to execute the application.
  6. Then installed electron-packager using npm install electron-packager.
  7. Now the problem is coming in this step when i am trying to pacakge the app using command electron-packager .
Nodababus answered 14/7, 2017 at 8:6 Comment(1)
npm install -g electron-packagerConnieconniption
H
43

Perform a global package install:

npm install -g electron-packager

The -g flag tells NPM to install the package globally which makes the command electron-packager available in your PATH.


If you don't want to do a global install you can install it locally and run with npx.

npm install -D electron-packager 

npx electron-packager .

Alternatively, you can reference it straight from the node_modules folder (not recommended).

./node_modules/electron-packager/cli.js
Herzen answered 14/7, 2017 at 21:8 Comment(0)
V
6

There are two cases to make it work...

  1. As discussed above, install electron globally using -g,

    i.e. using npm install -g electron-packager

  2. Change in your package.json:

   "scripts": {
     "start": "electron-packager ."
   },

Then type in the command npm start.

This way it worked for me..

Vannoy answered 22/8, 2018 at 7:35 Comment(0)
I
2

If you have installed it locally with:

npm install electron-packager

Then, it's not gonna work, install it globally as a cli:

npm install -g electron-packager

You can also get it through:

"node_modules/electron-packager/cli.js" . --all --asar

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:

...
    "scripts": {
    "start": "electron .",
    "build": "electron-packager . --asar --all"
  },
...

Then, go in command prompt or terminal or bash. Then, type:

npm run build
Iseult answered 28/8, 2019 at 6:21 Comment(0)
T
1

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

Trost answered 21/3, 2019 at 16:10 Comment(1)
Thank you!You absolutly right.I ignored space too and got the same errorBukharin
B
0

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 OR npm i -g electron-packager //i stands for install

Bemuse answered 20/2, 2019 at 13:18 Comment(0)
F
0

In my case it doesn't worked after npm global installation.

On the electron-builder Readme page it's recommended to install with yarn.

Yarn is strongly recommended instead of npm.
yarn add electron-builder --dev

Also we can put folder directly to PATH. On Windows 10:

  1. Search with word "environment" and open Edit the environment variables.
  2. Select, edit and Add new value C:\Users\USER_NAME\AppData\Roaming\npm to variable Path. Replace USER_NAME with your Windows username.

Then we might need to restart or logout.

Also in my case I enabled script execution on Windows 10 with instruction on answer below:

PowerShell says "execution of scripts is disabled on this system."

Flocculate answered 10/6, 2020 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.