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

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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:

  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 .

回答1:

npm install -g electron-packager

You need the -g flag to install it 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



回答2:

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 ." }, and then give command npm start.

This way it worked for me..



回答3:

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



回答4:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!