electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box

Home Page:https://www.electron.build

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Application entry file reset to default (react-cra detected and config changed incorrectly)

synapse opened this issue · comments

  • 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

Please set env DEBUG=electron-builder and attach log of the terminal output.

> logbook@0.2.0 pack /Users/Synapse/Documents/Projects/React/Notes
> set env DEBUG=electron-builder && build

electron-builder 19.24.1
⚠️  public/electron.js not found. Please see https://medium.com/@kitze/%EF%B8%8F-from-react-to-an-electron-app-ready-for-production-a0468ecb1da3
No native production dependencies
⚠️  Packaging using asar archive is disabled — it is strongly not recommended.
Please enable asar and use asarUnpack to unpack files that must be externally available.
Packaging for darwin x64 using electron 1.7.5 to dist/mac
⚠️  Application icon is not set, default Electron icon will be used
Error: Application entry file "build/electron.js" does not exist. Seems like a wrong configuration.
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/platformPackager.ts:325:15
From previous event:
    at MacPackager.checkFileInPackage (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/platformPackager.js:376:11)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/platformPackager.ts:349:16
    at next (native)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/graceful-fs/polyfills.js:287:18
    at FSReqWrap.oncomplete (fs.js:123:15)
From previous event:
    at MacPackager.sanityCheckPackage (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/platformPackager.js:394:11)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/platformPackager.ts:194:16
    at next (native)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at MacPackager.doPack (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/platformPackager.js:254:11)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/macPackager.ts:92:71
    at next (native)
From previous event:
    at MacPackager.pack (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/macPackager.js:190:11)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/packager.ts:253:24
From previous event:
    at Packager.doBuild (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/packager.js:340:11)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/packager.ts:184:52
    at next (native)
From previous event:
    at Packager.build (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/packager.js:259:11)
    at /Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/builder.ts:266:40
    at next (native)
From previous event:
    at build (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/out/builder.js:69:21)
    at loadEnv.then (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/cli/cli.ts:49:4)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at Object.args [as handler] (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/cli/cli.ts:49:4)
    at Object.self.runCommand (/Users/Synapse/Documents/Projects/React/Notes/node_modules/yargs/lib/command.js:233:22)
    at Object.Yargs.self._parseArgs (/Users/Synapse/Documents/Projects/React/Notes/node_modules/yargs/yargs.js:1018:24)
    at Object.get [as argv] (/Users/Synapse/Documents/Projects/React/Notes/node_modules/yargs/yargs.js:927:19)
    at Object.<anonymous> (/Users/Synapse/Documents/Projects/React/Notes/node_modules/electron-builder/src/cli/cli.ts:43:15)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:504:3

npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "pack"
npm ERR! node v6.11.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! logbook@0.2.0 pack: `set env DEBUG=electron-builder && build`
npm ERR! Exit status 255
npm ERR!
npm ERR! Failed at the logbook@0.2.0 pack script 'set env DEBUG=electron-builder && build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the logbook package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     set env DEBUG=electron-builder && build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs logbook
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls logbook
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/Synapse/Documents/Projects/React/Notes/npm-debug.log

Workaround: please add "extends": null to build.

Worked, thanks

@develar Thanks, you fixed my problem. Do you mind briefly explaining why adding "extends": null works and why all of a sudden I was having this issue? The current documentation about the extends option is not too helpful.

I'm in the same boat as @genepool99, I'm interested in understanding what exactly the change is doing.

Added "extends: null" to my build and the error disappeared and now I get Error: Application entry file "index.js" ... does not exist ..

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?

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:

If react-scripts in the app dependencies, react-cra will be set automatically. Set to null to disable automatic detection.

@v-rumak yep! thank you so much!

make sure guys to build electron app before run the builder comment. specially if using ts.

@genepool99 @mhuggins, when we create a electron app with create-react-app, extends will set to "react-cra" automatically, as the official document wrote:

extends String - The name of a built-in configuration preset or path to config file (relative to project dir). Currently, only react-cra is supported.

If react-scripts in the app dependencies, react-cra will be set automatically. Set to null to disable automatic detection.

In the "react-cra" mode, the entry file will be set to "build/electron.js", while building, we don't have this file in the build folder, so this will cause the error.

So set extends to null will remove this default entry point, the build will be fine.

Workaround: please add "extends": null to build.

Worked, thank you so much.

works, thanks.

I was having the same issue with CRA and setting build.extraMetadata.main to my app's entry file fixed this issue for me without setting build.extends to null.

here's it from my package.json file:

"build": {
  "extraMetadata": {
    "main": "build/main.js"
  }
}

where "build/main.js" is my electron's entry file.

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:

    "appId": "com.electron.xxx",
    "mac": {
      "category": "your.app.category.type"
    },
    "files":[
      "./main.tsx"
    ],
    "extraMetadata": {
      "main": "main.tsx"
    }
  }`

for me it worked including the files directly

"build": { "files": [ "build/**/*", "node_modules/**/*" ],

Workaround: please add "extends": null to build.

worked, thx

commented
image there my config const builder = require("electron-builder"); const Platform = builder.Platform;

builder.build({
targets: Platform.WINDOWS.createTarget(),
config: {
extraMetadata: {
main: './index.js'
},
productName: "wms",
appId: "com.wms.wms",
copyright: "wms",
directories: {
output: "build",
},
win: {
"icon": "../build/logo512.png",
target: [
{
target: "nsis",
},
],
},
},
});