问题及步骤描述:
根据Electron官网步骤进行打包时:
npx @electron-forge/cli import
命令提示:
√ Checking your system
It looks like you are missing some dependencies you need to get Electron running.
Make sure you have git installed and Node.js version >= 10.0.0
从git官网下载安装git后,打开git bash再次执行命令:
npx @electron-forge/cli import
命令提示:
- Checking your system
√ Checking your system
- Initializing Git Repository
√ Initializing Git Repository
- Writing modified package.json file
√ Writing modified package.json file
- Installing dependencies
× Installing dependencies
An unhandled error has occurred inside Forge:
Failed to install modules: ["electron-squirrel-startup"]
With output: Command failed with a non-zero return code (4294963238):
npm install electron-squirrel-startup --save
根据提示执行命令:
npm install electron-squirrel-startup --save
成功后再次执行命令:
npx @electron-forge/cli import
成功!
$ npx @electron-forge/cli import
- Checking your system
√ Checking your system
- Initializing Git Repository
√ Initializing Git Repository
- Writing modified package.json file
√ Writing modified package.json file
- Installing dependencies
√ Installing dependencies
- Writing modified package.json file
√ Writing modified package.json file
- Fixing .gitignore
√ Fixing .gitignore
We have ATTEMPTED to convert your app to be in a format that electron-forge understands.
Thanks for using "electron-forge"!!!
还没完,按照官网的步骤创建分发版本:
$ npm run make
> my-electron-app@1.0.0 make E:\Workspace\VSCode\my-electron-app
> electron-forge make
- Checking your system
√ Checking your system
- Resolving Forge Config
√ Resolving Forge Config
We need to package your application before we can make it
- Preparing to Package Application for arch: x64
An unhandled rejection has occurred inside Forge:
PackageNotFoundError: Cannot find the package "electron". Perhaps you need to run "npm install" in "E:\Workspace\VSCode\my-electron-app"?
at getElectronVersion (E:\Workspace\VSCode\my-electron-app\node_modules\@electron-forge\core\src\util\electron-version.ts:102:13)
at _default (E:\Workspace\VSCode\my-electron-app\node_modules\@electron-forge\core\src\api\package.ts:186:22)
at _default (E:\Workspace\VSCode\my-electron-app\node_modules\@electron-forge\core\src\api\make.ts:156:5)
at E:\Workspace\VSCode\my-electron-app\node_modules\@electron-forge\cli\src\electron-forge-make.ts:44:5
...
根据提示执行:
$ npm install
npm WARN my-electron-app@1.0.0 No description
npm WARN my-electron-app@1.0.0 No repository field.
removed 2 packages in 2.95s
46 packages are looking for funding
run `npm fund` for details
这下总可以了把,再次分发:
$ npm run make
> my-electron-app@1.0.0 make E:\Workspace\VSCode\my-electron-app
> electron-forge make
- Checking your system
√ Checking your system
- Resolving Forge Config
√ Resolving Forge Config
We need to package your application before we can make it
- Preparing to Package Application for arch: x64
没错,卡住了,等了几分钟没跳出下一行提示。
题外话,上面的命令都是在git bash中运行的,此时如果回到vs code,会发现package.json被修改,原来的
"start": "electron ."
变成了"start": "electron-forge start"
,没错,你现在甚至运行不了项目了,我他喵佛了。建议新建一个项:"start:main": "electron ."
,此时运行还会报错,删去node_modules
目录,重新npm install
安装,看你网速可能又是折磨,等不下去试试安装cnpm
,安装好之后运行start:main
即可正常启动项目。
以为出bug了,重开了几次,后来挂机一会显示出结果:
$ npm run make
> my-electron-app@1.0.0 make E:\Workspace\VSCode\my-electron-app
> electron-forge make
- Checking your system
√ Checking your system
- Resolving Forge Config
√ Resolving Forge Config
We need to package your application before we can make it
- Preparing to Package Application for arch: x64
√ Preparing to Package Application for arch: x64
- Preparing native dependencies
√ Preparing native dependencies
- Packaging Application
√ Packaging Application
Making for the following targets: squirrel
- Making for target: squirrel - On platform: win32 - For arch: x64
× Making for target: squirrel - On platform: win32 - For arch: x64
An unhandled error has occurred inside Forge:
An error occured while making for target: squirrel
Failed with exit code: 1
Output:
正在尝试从“my_electron_app.nuspec”生成程序包。
Authors is required.
Description is required.
...
好,加上Authors和Description,再次分发:
$ npm run make
> my-electron-app@1.0.0 make E:\Workspace\VSCode\my-electron-app
> electron-forge make
- Checking your system
√ Checking your system
- Resolving Forge Config
√ Resolving Forge Config
We need to package your application before we can make it
- Preparing to Package Application for arch: x64
√ Preparing to Package Application for arch: x64
- Preparing native dependencies
√ Preparing native dependencies
- Packaging Application
√ Packaging Application
Making for the following targets: squirrel
- Making for target: squirrel - On platform: win32 - For arch: x64
√ Making for target: squirrel - On platform: win32 - For arch: x64
好耶!
注意:
author
和description
字段对于打包来说是必要的,否则运行npm run make
命令时会报错。