angular 5 with electron-packager

倖福魔咒の 提交于 2021-01-25 07:30:32

问题


I try to build my electron project to window app by using electron-packager but I get this error.

Failed to locate module "fsevents" from "/var/www/windowapp/electron-angular-project/node_modules/@angular-devkit/core/node_modules/chokidar"

    This normally means that either you have deleted this package already somehow (check your ignore settings if using electron-packager).  Or your module installation failed.

Anyone know how to solve it and what happened to this?


回答1:


Here my 2 cent, I did a package that works without the error, but also avoids to add unnecessary files:

electron-packager . --no-prune --ignore=/node_modules --ignore=/e2e --ignore=/src

The electron-packager expect that you have already run run the angular build process:

ng build --prod

You can add this script in the package.json:

"electron-package": "ng build --prod && electron-packager . --no-prune --ignore=/node_modules --ignore=/e2e --ignore=/src --overwrite"

Then run:

npm run electron-package



回答2:


With slight modification on the answer provided by Michael Denny "electron-package": "ng build --prod && electron-packager . --no-prune --ignore=/node_modules --ignore=/e2e --ignore=/src --overwrite" I'm able to package my electron angular 7 application. Please note, minor modifications might require on these commands, on a case to case to basis. In my case, the following command worked.

"electron-package": "ng build --prod --base-href ./ && electron-packager . --no-prune --ignore=/e2e --ignore=/src --overwrite"

What is the change?

Removed --ignore=/node_modules
Reason: if I add this option while building, Ended up in Module Not Found Error

Added --base-href ./
Reason: Otherwise, Ended up with error Failed to load resource: net::ERR_FILE_NOT_FOUND

With these two modifications, I'm able to package my electron angular 7 application. Size of the package is close to 100MB. I'm looking for a way to reduce this size.




回答3:


In the directory where your app is, try run this command

electron-packager . --no-prune

More information about this commands can be found in here https://github.com/electron-userland/electron-packager/blob/master/usage.txt




回答4:


This is related to the issue #821in electron-packager with removing optional platform specific dependencies (possibly only when running packager on Windows).

--no-prune solves the problem during development, but won't work for production.

Reverting to v11.2.0 also solves the issue.



来源:https://stackoverflow.com/questions/49643270/angular-5-with-electron-packager

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