How to publish electron app to GitHub releases using electron builder? - electron

I am trying to publish my electron app to GitHub releases but I cannot get it to work.
This is what I have:
package.json
....
"scripts": {
"start": "electron . --disable-gpu",
"test": "echo \"Error: no test specified\" && exit 1",
"win": "electron-builder --windows nsis:ia32",
"linux": "electron-builder --linux",
"publish":"electron-builder -p onTag"
},
....
"build": {
"publish": [
"github"
],
....
}
when I run npm run publish it creates the executable but it does not publish on my GitHub releases repository:
$ npm run publish
> Inventory-pro#1.0.1 publish /home/xander/Develop/Electron/InventoryV2
> electron-builder -p onTag
• electron-builder version=21.2.0 os=5.3.0-26-generic
• loaded configuration file=package.json ("build" field)
• writing effective config file=dist/builder-effective-config.yaml
• packaging platform=linux arch=x64 electron=7.1.3 appOutDir=dist/linux-unpacked
• building target=deb arch=x64 file=dist/Inventory-pro_1.0.1_amd64.deb
I want to publish it so that I can include auto-update on my app on every release.

Don't specify the -p option and it will always publish a release because your script in the package.json is named release.
But please consider using automatic rules instead of explicitly specifying publish:
If npm script named release, — always.
Source: https://www.electron.build/configuration/publish#how-to-publish
...
"scripts": {
...
"publish":"electron-builder"
},
...

Related

Build electron as exe on macbook m1

I trying to build an electron with an exe installer on macOS with a MacBook Pro with an m1. I already tried different packages like electron-packager, electron-forge, but unfortunately, none of my tries worked. Did anyone has a solution to build an electron version with an exe on macOS.
My latest approach looked like, but when I start and after more then 30 minute it still do no finish.
yarn run electron-forge make --arch=x64 --platform=win32
The current code could be found here.
We using electron-builder for packaging electron app on Windows&MacOS(x86_x64/arm etc.), and you can try it.
add some config in package.json, like this:
"build": {
"appId": "com.electron.yourappid",
"productName": "your-product-name",
"asar": false,
"mac": {
"target": [
"pkg"
],
"entitlements": "entitlements.mac.plist"
},
"win": {
"target": [
{
"target": "zip",
"arch": [
"x64"
]
},
{
"target": "msi",
"arch": [
"x64"
]
}
]
}
},
"scripts": {
"dist": "electron-builder"
},
then run npm command like this:
# add package in your project
npm install --save-dev electron-builder
npm run dist # or 'npx electron-builder'
If you perfer using 'shelljs', create a file 'dist.js', and content:
const { exec, rm } = require('shelljs');
exec('electron-builder');
and then run node command
npm install --save-dev shelljs
node dist.js
More detail for config you can read offical doc of electron-builder.
I've looked into it and failed (building Apple Silicon, Apple Intel and Windows distributables from M1 Mac). I ended up setting up VMs that I use for building the distributables, and testing also.
electron-builder 23.0.3 and flag --universal work for me on Macbook M1 2021
This works for me. npx electron-builder --win --x64

npm run make is not working in electron-forge

I have created and electron application and trying to use electron forge for building purpose.
Please find below command which i have run it for creating the electron application:
#npm i -g create-react-app
#npm i -g #electron-forge/cli
#npx create-electron-app my-ele-app
The above last command created a project my-ele-app. and now i am able to start the application as well.
#npm start.
content of package.json file is:
{
"name": "my-ele-app",
"productName": "my-ele-app",
"version": "1.0.0",
"description": "My Electron application description",
"main": "src/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish",
"lint": "echo \"No linting configured\""
},
"keywords": [],
"author": {
"name": "rohit",
"email": "rohit#xyz.com"
},
"license": "MIT",
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "#electron-forge/maker-squirrel",
"config": {
"name": "my_ele_app"
}
},
{
"name": "#electron-forge/maker-zip",
"platforms": [
"darwin"
]
},
{
"name": "#electron-forge/maker-deb",
"config": {}
},
{
"name": "#electron-forge/maker-rpm",
"config": {}
}
]
}
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
},
"devDependencies": {
"#electron-forge/cli": "^6.0.0-beta.55",
"#electron-forge/maker-deb": "^6.0.0-beta.55",
"#electron-forge/maker-rpm": "^6.0.0-beta.55",
"#electron-forge/maker-squirrel": "^6.0.0-beta.55",
"#electron-forge/maker-zip": "^6.0.0-beta.55",
"electron": "12.0.9"
}
}
Now when i am running below command, it is throwing error:
#npm run make
Error is:
> my-ele-app#1.0.0 make
> electron-forge make
√ Checking your system
√ Resolving Forge Config
An unhandled rejection has occurred inside Forge:
Error: Could not find module with name: #electron-forge/maker-squirrel. Make sure it's listed in the devDependencies of your package.json
at _default (C:\Users\212807091\Desktop\Rohit\Office Note\RBAC\Electron_project\npx_electrong\my-ele-app\node_modules\#electron-forge\core\src\api\make.ts:125:15)
at C:\Users\212807091\Desktop\Rohit\Office Note\RBAC\Electron_project\npx_electrong\my-ele-app\node_modules\#electron-forge\cli\src\electron-forge-make.ts:44:5
Electron Forge was terminated. Location:
{}
NOTE: i can see there is module available in node_modules folder:
my-ele-app\node_modules#electron-forge\maker-squirrel
If anyone here has any idea how to fix this issue. please provide the answer. Thanks!
In my cases, it makes error when the description or author is empty in package.json file.
I got the same error after following the "Getting Started" instructions. Nothing resolved it until I ran npm install -g #electron-forge/cli#beta -- after that finished I was able to successfully run electron-forge make.
Also running npm run make did the same as electron-forge make as I didn't appear to have it installed. Another thing I noticed is that if I run npm run make with maker-squirrel at version 6.0.0-beta.55 then I get this error: Could not find module with name: #electron-forge/maker-squirrel. However, if I re-install maker-squirrel as npm install --save-dev #electron-forge/maker-squirrel#6.0.0-beta.33 and re-run npm run make then I get an out folder with an exe.
you have installed all the required dependencies so just run this command
npm run package
And after this a folder with name out is generated and inside that your .exe file will be present
I had a similar issue but I followed the instructions from here: https://www.electronjs.org/docs/latest/tutorial/quick-start#package-and-distribute-your-application
I missed calling npx electron-forge import. So the full pipeline looks like this:
npm install --save-dev #electron-forge/cli
npx electron-forge import
npm run make
Check the documentation. i solve same problem with this
If you are using Windows, this works for me:
Run npm i electron-winstaller --save-dev --ignore-scripts
Install 7zip x86 in your computer. After installed, go to C:\Program Files (x86)\7-Zip and copy both 7z.dll and 7z.exe files to /path/to/your_project/node_modules/electron-winstaller/vendor if they are not still there.
Run npm electron-forge import again
Then try run npm run make again. I hope it works.

electron-installer-debian compiled app .deb won't run

My compiled app don't run and i don't know why ...
electron-installer-debian -> 3.0.0
node -> 8.16.0
npm -> 6.4.1
operating system ->ubuntu 16.04.6 amd64
I can compile the example app successfully.
I can compile my app successfully.
What did i do
package.json content
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron .",
"build": "electron-packager . electron-quick-start --platform linux --arch x64 --out dist/",
"deb64": "electron-installer-debian --src dist/electron-quick-start-linux-x64/ --dest dist/installers/ --arch amd64"
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
"Electron",
"quick",
"start",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "CC0-1.0",
"devDependencies": {
"electron": "^8.2.5",
"electron-installer-debian": "^3.0.0",
"electron-packager": "^14.2.1"
}
}
I compile my app successfullt by executing npm run build to build my app with electron-packager then i do npm run deb64 to compile my code.
It return a successfull sentence.
Then i find my electron-quick-start_1.0.0_amd64.deb in the dist/installers folder and install it successfully (no error of any kind).
What did you expect to happen?
I expect to run my app by searching it in the ubuntu search bar.
What actually happened?
The app juste don't run. No error pop up. Nothing ... :'(
Even if i try to run it from terminal
see the image
electron-installer-debian creates dab file which by default installs your app in usr/lib folder. If you navigate to usr/lib//resources/ give permissions to your app folder your app should work, but this is not recommended for security reasons.

How to use electron-builder with target portable?

I am trying to generate a exe file with electron-builder not an installer so I am trying by setting the target to portable
{
"name": "hello-world",
"version": "1.0.0",
"description": "a hello world",
"main": "index.js",
"scripts": {
"start": "electron .",
"dist": "build"
},
"author": "KR",
"license": "ISC",
"devDependencies": {
"electron": "^4.1.4",
"electron-builder": "^20.39.0"
},
"build":{
"appId": "com.whatever.helloworld",
"win":{
"target": ["portable"],
"icon" : "build/icon.ico"
}
}
}
However when I try npm run dist I get
Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
• electron-builder version=20.39.0
• loaded configuration file=package.json ("build" field)
• writing effective config file=dist\builder-effective-config.yaml
• no native production dependencies
• packaging platform=win32 arch=x64 electron=4.1.4 appOutDir=dist\win-unpacked
• default Electron icon is used reason=application icon is not set
• building target=portable file=dist\hello-world 1.0.0.exe archs=x64
and the program is stuck for ever. When I break it(ctrl-c), it says
Error: Exit code: 255. Command failed: D:\electrontest\hello-world\node_modules\7zip-bin\win\x64\7za.exe a -bd -mx=9 -mtc=off -mtm=off -mta=off D:\electrontest\hello-world\dist\hello-world-1.0.0-x64.nsis.7z .
So I guess the program is stuck in 7za compression.
I searched and there is no example of using electron-builder with portable only few with nsis. (I have another question but first I would like to run the basics).
use electron-builder from 1
then in package.json use in scripts:
"dist": "electron-builder --win=portable",

Electron-builder release tries to publish to Github and complains about GH_Token

running the release script without publish option tries to publish the build to GitHub ( and fails while complaining about not being able to find GHToken! )
Error: GitHub Personal Access Token is not set, neither programmatically, nor using env "GH_TOKEN"
Setting "publish": "never" will fail also complaining about not being able to find module electron-publisher-never!
Error: Cannot find module 'electron-publisher-never'
It all happens while the project is built but build scripts exits non-zero!
I'm using the latest version of electron-builder.
my build script:
"build": {
"appId": "eu.armand.[****]",
"copyright": "Copyright © 2017 mim_Armand",
"productName": "[****]",
"mac": {
"publish": "never",
"category": "public.app-category.[****]",
"icon": "assets/icons/mac/icon.icns"
}
Any idea what's going on or if I'm doing it wrong?!
,m
try building with
"build": "electron-builder --publish never"
to never publish.
rename your script to something else.
if the script name is release → publish is set to always
the documentation states this:
CLI --publish option values:
...
If npm script named release, — always.
Add to scripts in the development package.json:
"release": "build"
and if you run yarn release, a release will be drafted (if doesn’t
already exist) and artifacts published.
I solved it this way, because I didn't need to put it in any repository
"build":{
"appId": "XXX",
"productName": "XXX",
"directories":{
"output": "build"
},
"win":{
"target": "nsis",
"publish" : []
}
}
https://www.electron.build/configuration/publish

Resources