在Ubuntu 17.10上我正在安装和运行这样的电子:
ole@mki:~/angular-electron$ npm i --save-dev electron
> electron@1.7.12 postinstall /home/ole/angular-electron/node_modules/electron
> node install.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ electron@1.7.12
updated 1 package in 19.956s
ole@mki:~/angular-electron$ electron
electron: command not found
安装后Ubuntu无法找到电子命令。想法?
答案 0 :(得分:3)
When running npm i --save-dev electron
the package will be installed in /home/ole/angular-electron/node_modules/electron
(as you can see). To execute the binary you need to run /home/ole/angular-electron/node_modules/.bin/electron
or $(npm bin)/electron
.
I propose that you'll add a script in your package.json
to run electron, for example:
"scripts": {
"start": "electron"
}
npm will then automatically look into node_modules/.bin
.
答案 1 :(得分:2)
This might be a little bit confusing but in general, there are 2 ways how to run npm packages.
You can install the package globally npm install
your-package-name -g
You can install the package locally npm install
your-package-name
and then run it from
/node_modules/.bin/electron
If you install your package locally you have also two options how to run the package from command line:
Directly from node_modules
like this: ../node_modules/.bin/electron
You can create a script
command in your
package.json:
"scripts": {
"your-script-name": "electron"
}
then if you run npm run your-script-name
npm
will first look in the .bin
directory and if it finds electron
it will run it. Otherwise it will look at your global dependencies.
However, it is important not to forget that this command:
"your-script-name": "do-something && electron"
will also run electron
globally. If you want to run electron locally you can either split the command into two separate commands or change electron
to npm run electron
like this:
"your-script-name": "do-something && npm run electron"