'电子包装机'不被视为内部或外部命令

时间:2017-07-14 08:06:26

标签: npm electron electron-packager

我最近开始使用电子。我通过创建一个hello world app(包含文件index.html,main.js,package.json)成功完成了第一阶段。现在我正在尝试使用electron-packager打包应用程序,但收到此错误

electron-packager error

我遵循的步骤:

  1. 创建了一个名为helloworld的项目目录。
  2. 使用npm init命令初始化项目目录。
  3. 然后使用npm install electron --save-dev安装电子。
  4. 然后分别将javascript和html文件创建为main.js和index.html。
  5. 然后使用npm start执行应用程序。
  6. 然后使用npm install electron-packager安装了electron-packager。
  7. 现在,当我尝试使用命令electron-packager .
  8. 来宣传应用程序时,问题就出现了

6 个答案:

答案 0 :(得分:19)

npm install -g electron-packager

您需要-g标志才能全局安装它,这使得PATH中的命令electron-packager可用。

如果您不想进行全局安装,可以在本地安装并使用npx运行。

npm install -D electron-packager

npx electron-packager .

或者,您可以直接从node_modules文件夹中引用它(不推荐)。 ./node_modules/electron-packager/cli.js

答案 1 :(得分:1)

如果您是通过以下方式在本地安装的:

npm install electron-packager

然后,它将不起作用,将其作为cli全局安装:

npm install -g electron-packager

您也可以通过以下方式获取它:

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

毕竟,如果您无法正常工作,请安装electron-packager。 然后,转到您的package.json。在您的启动脚本下方。创建另一个名为“ build”的字符串,并为其提供您要运行的电子包装程序命令的值:

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

然后,进入命令提示符或终端或bash。 然后,输入:

npm run build

答案 2 :(得分:0)

有两种情况可以使其起作用...

  1. 如上所述,使用-g全局安装电子, 即使用npm install -gelectron-packager

  2. package.json中的更改,  “脚本”:{ “ start”:“电子包装机”。 }, 然后给命令npm start。

这样对我有用。

答案 3 :(得分:0)

您必须在全球范围内安装电子包装机,这就是为什么它显示 Lets say i have created four indexes 1) distributor-info 2) product-info 3) store-info 4) store-distributor-map index Mapping 1)PUT /product_info `{ "mappings": { "products": { "properties": { "id": {"type": "text" }, "product": { "type": "text" }, "distributor": { "type": "text" }, "location": { "type": "text" }, "stock": { "type": "text" }, "description": { "type": "text" }, "user-Id": { "type": "text" } } } } }` 2) PUT /store-distributor-map `{ "mappings": { "products": { "properties": { "storeid": {"type":"text"}, "distributorIds":{"type":"nested"} } } } }` 3) PUT /distributor-info `{ "mappings": { "products": { "properties": { "distributor-Id": {"type": "text" }, "name": { "type": "text" }, "location":{"type": "text" } } } } }` 4)PUT /store-info `{ "mappings": { "products": { "properties": { "storeid":{"type":"text"}, "distributorIds":{"type":"nested"} } } } }`

为此,您必须全局安装电子包装

您可以使用-g选项进行全局安装。

示例:- 'electron-packager' is not recognized as an internal or external command npm install -g electron-packager //我代表安装

答案 4 :(得分:0)

我可能对此完全不满意,但我的解决方法是我将点放在无空格的地方,只是确保在package.json文件中确保其“开始”:“电子”。 至少对我来说已解决

答案 5 :(得分:0)

对于我来说,在npm全局安装后它不起作用。

在电子生成器自述文件页面上,建议安装纱线。

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

我们也可以将文件夹直接放入PATH。在Windows 10上:

  1. 用单词“ environment”搜索,然后打开“编辑环境变量”。
  2. 选择,编辑新值C:\ Users \ USER_NAME \ AppData \ Roaming \ npm并将其添加到变量Path。用您的Windows用户名替换USER_NAME。

然后我们可能需要重新启动或注销。

就我而言,我还在Windows 10上启用了脚本执行,并在下面给出了答案的说明:

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