electron-builder: Application entry file reset to default (react-cra detected and config changed incorrectly)
- Version: 19.24.1
- Target: OSX
Hi, I have an issue where every time i run build it resets the package.json to the default path build/electron.js and thus giving me this error: Error: Application entry file "build/electron.js" does not exist. Seems like a wrong configuration.
this is my initial package.json
{
"name": "xxx",
"description": "xxx",
"version": "0.2.0",
"private": true,
"author": "XXX",
"updateURL": "xxx",
"homepage": ".",
"main": "main.js",
"build": {
"asar": false,
"productName": "xxx",
"appId": "com.xxx.xxx",
"files": [
{
"from": ".",
"to": ".",
"filter": [
"electron",
"images",
"node_modules",
"main.js",
"package.json"
]
},
{
"from": "./xxx/build",
"to": ".",
"filter": ["**/*"]
}
],
"mac": {
"artifactName": "${productName}-${version}-osx.${ext}",
"category": "public.app-category.productivity",
"target": [
"dmg",
"zip"
]
},
"linux": {
"artifactName": "${productName}-${version}-${arch}-linux.${ext}",
"maintainer": "xxxx",
"target": [
"tar.gz",
"deb",
"rpm"
]
},
"win": {
"target": [
"zip",
"dir"
]
}
},
"dependencies": {
"asar": "^0.13.0",
"electron-updater": "^2.4.4",
"fs-extra": "^3.0.1",
"moment": "^2.18.1",
"mv": "^2.1.1",
"node-notifier": "^5.1.2"
},
"devDependencies": {
"electron": "^1.7.5",
"electron-builder": "^19.24.1",
"react-scripts": "^1.0.11"
},
"scripts": {
"clean": "node ./build/clean",
"build": "",
"pack": "build"
}
}
To
{
"name": "xxx",
"description": "xx",
"version": "0.2.0",
"private": true,
"author": "xxx",
"updateURL": "xxx",
"homepage": ".",
"main": "build/electron.js",
"dependencies": {
"asar": "^0.13.0",
"electron-updater": "^2.4.4",
"fs-extra": "^3.0.1",
"moment": "^2.18.1",
"mv": "^2.1.1",
"node-notifier": "^5.1.2"
}
}
this is my folder structure
assets
build
cache
dist
electron
images
logbook
main.js
node_modules
package.json
website
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (2 by maintainers)
Commits related to this issue
- https://github.com/electron-userland/electron-builder/issues/2030 — committed to kimsk/electron-react-typescript by deleted user 6 years ago
- Fix with the workaround from https://github.com/electron-userland/electron-builder/issues/2030#issuecomment-327155801 — committed to baruchiro/israeli-bank-scrapers-desktop by baruchiro 4 years ago
- Fix with the workaround from https://github.com/electron-userland/electron-builder/issues/2030#issuecomment-327155801 — committed to SuperStar511/Israeli-bank-react by SuperStar511 4 years ago
Workaround: please add
"extends": nulltobuild.I was having the same issue with CRA and setting
build.extraMetadata.mainto my app’s entry file fixed this issue for me without settingbuild.extendstonull.here’s it from my
package.jsonfile:where
"build/main.js"is my electron’s entry file.For those who are using react in your app, you should use “react-scripts build” before trying to run electron-builder… “react-scripts build” will generate “build” folder which used by electron-builder(when preset=react-cra)… For those, who don’t - you should set “extends”: null, to avoid situation, when “preset=react-cra”. When this situation is possible? Quote from documentation:
@develar Thanks, you fixed my problem. Do you mind briefly explaining why adding
"extends": nullworks and why all of a sudden I was having this issue? The current documentation about theextendsoption is not too helpful.I am having the exact same issue. I have tried all fixes suggested above, but none of them work for me. Any updates for this?
As always, make sure you double-check the casing on your file names… too embarrassed to say how much time I just sunk into this. 😭
For me it solved by : pass in the entry file path externally, using files param then over write the “main” with that file name using extraMetadata param
as follows:
make sure guys to build electron app before run the builder comment. specially if using ts.