how can i package an electron app for linux? - electron

I have been using electron to make desktop application for a while now but still can't figure out how it can be packaged for all the available linux distributions

For ALL linux distributions I have no idea. The way I make mine Linux Electron projects is just
npm install --save-dev electron-builder
add this to the root of my package.json
"build": {
"appId": "com.myname.appname",
"asar": true,
"mac": {
"category": "public.app-category.developer-tools"
}
},
I make a build folder in the root and put
icon.icns
icon.ico
which I built from this site
and then
./node_modules/.bin/electron-builder
it puts an .AppImage file in dist
more instructions here

Related

electron-builder fails building linux package on macos - Error: Unknown target: build

I'm using electron-builder to package my application. I have a dist/ folder where all resources are. main.js in root folder does not need any transpiling and includes main process code. This works well in development mode when launching using electron command.
I have electron-builder set up using package.json configuration:
[...]
"main": "./main.js",
"build": {
"appId": "com.electron.mycompany.myapp",
"productName": "myapp",
"linux": {
"target": "deb"
},
"files": [
"./dist",
"./main.js"
]
},
[...]
I'm launching electron-builder like this: electron-builder -ml build. Macos build packages fine and I'm able to launch the application. However Linux build fails. I'm building Linux package on macos Catalina. It gives me error stack trace:
rebuilding native dependencies dependencies=leveldown#5.6.0 platform=linux arch=x64
⨯ Unknown target: build stackTrace=
Error: Unknown target: build
at createCommonTarget (/Users/username/Projects/myappnode_modules/app-builder-lib/src/targets/targetFactory.ts:90:11)
at /Users/username/Projects/myapp/node_modules/app-builder-lib/src/linuxPackager.ts:65:18
at mapper (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/targets/targetFactory.ts:57:16)
at LinuxPackager.createTargets (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/linuxPackager.ts:63:7)
at createTargets (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/targets/targetFactory.ts:64:12)
at Packager.doBuild (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/packager.ts:442:28)
at processTicksAndRejections (internal/process/task_queues.js:85:5)
at executeFinally (/Users/username/Projects/myapp/node_modules/builder-util/src/promise.ts:12:14)
at Packager._build (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/packager.ts:373:31)
at Packager.build (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/packager.ts:337:12)
at executeFinally (/Users/username/Projects/myapp/node_modules/builder-util/src/promise.ts:12:14)
• building embedded block map file=dist/IJP Visualization Tool-1.0.0-alpha.1-mac.zip
I am not using any code signing (nor do I wish to). Is something misconfigured? It seems to be it but not sure what the problem is exactly.
As per the electron-builder CLI documentation, all platform switches accept a "target list", which in essence is what you configure in your package.json with your different platform entries (build.<platform>.target, e.g. build.linux.target).
However, by using these target lists, you can specify which targets you want to build and exclude all others. Since Linux' switch is the last in the switch list -ml, Electron Builder interprets this as though you want to pass it a target list. This does not apply to the macOS build step because then you would have to use -m <targets> -l <targets>, -ml <targets> apparently only applies to Linux.
Thus, by appending build to the command line, you tell Electron Builder to compile all configured targets for macOS but only build the Linux target called build. Since there is no such target, Electron Builder crashes. Removing build from your command will do the trick.

How to build only .app using electron-builder

I am trying to fix a tricky production issue in electron app.
And electron-builder takes around 5-6 minutes to build
project.app
project.dmg
project.mac.zip and so on.
Is there I can only build project.app and save time by not building .dmg file etc ?
Just add dir as target in your package.json
"build": {
"appId": "app.id",
"mac": {
"category": "your.app.category.type",
"target": "dir"
}
}
Not sure if you can avoid dmg and mac and only serve .app files but you can avoid generating both dmg and zip file by specifying the target option in mac build config
"mac": {
"target": [
"dmg"
],
},
If none of this work, you can always use a script to clean the .app file, run electron-builder as background process, then check until the .app file is built, kill the electron-builder process.

How to properly packaged an electron applications

what could be the best way to package an electron apps.
I have test and run my electron app and it works fine. Now I want to package my electron app but it just shows in command prompt
packaging app for platform win32 ia32 using electron v5.0.6 and nothing else as can be shown in the screenshot below.
when I check electron version via this code electron --version
it output v1.4.13 but during packaging it uses electron v5.0.6. Is this an electron version conflict or what?
here is my package.json
{
"name": "test-app",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"pretty-bytes": "^2.0.1"
},
"devDependencies": {
"electron": "^5.0.6",
"electron-prebuilt": "^0.35.2"
},
"scripts": {
"start": "electron main.js"
},
"author": "",
"license": "ISC"
}
can someone tell me what is wrong and why my electron app refuse to be packaged.
I found out that the code will eventually compile using electron-packager source Electron Packager. If users is compiling or packaging app for the first time, it can take up 30 minutes or more so the user has to be patient and it will package well. From the screenshot above, you can see that my app is already compiling just that I was impatient to see the end.
Waiting for about 30 minutes allows my system to finally package the app so am good to go now with electron. Thanks

Electron doesn't install all packages inside package.json

Electron packager has packaged my app.But it doesn't have all the node modules as present in my app before packaging. I am forced to manually run npm install inside my packaged folder.
So, the app is not able to perform as expected.
I tried inside package.json
"build": {
"files": [
"/node_modules/**",
"package.json"
]
}
It looks like you are using your package.json wrong way.
Only "dependencies" will be included to the build if you put some package to "devDependencies" it will be excluded from the build.
use no-prune in build using electron packager and place all the modules inside devDependencies and then build the app.

Why does my electron app doesn't launch after packaging?

I have problem with project(https://github.com/Gordienko-RU/plant-log), there are angular bundle in dist folder and electron main file into electron folder, but after packaging with electron-builder, application doesn't run.
I guess there are some problems with my config in to package.json
Ok, I had a similar issue with electron-packager. I tried your package.json and did a "npm install". To me it looks like that your build does include native addons (*.node).
In electron-packager the solution was to add the asar unpack option. You are using electron-builder. Therefore you should look at this thread: https://github.com/electron-userland/electron-builder/issues/390 . Maybe you need to specify the modules by hand, like:
"asar": true,
"asarUnpack": [
"../node_modules/uws"
]

Resources