electron-builder: Error: Application entry file "build/electron.js" in the "/dist/mac//Contents/Resources/app.asar" does not exist.

  • Version: 19.49.0

  • Target: mac

I’m using create-react-app and also followed below blog post. https://medium.com/@kitze/️-from-react-to-an-electron-app-ready-for-production-a0468ecb1da3

Error: Application entry file "build/electron.js" in the "/Users/jarvis/Dev/sandbox/elec-app/dist/mac/elec-app.app/Contents/Resources/app.asar" does not exist. Seems like a wrong configuration.
    at error (/Users/jarvis/Dev/sandbox/elec-app/node_modules/electron-builder-lib/src/asar/asarFileChecker.ts:7:12)
    at /Users/jarvis/Dev/sandbox/elec-app/node_modules/electron-builder-lib/src/asar/asarFileChecker.ts:33:11
    at next (native)
    at /Users/jarvis/Dev/sandbox/elec-app/node_modules/graceful-fs/polyfills.js:287:18
    at FSReqWrap.oncomplete (fs.js:123:15)
:

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 35
  • Comments: 39 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Somehow, setting files work

"build": {
    "files": [
      "dist/**/*",
      "package.json"
    ],
}

I was also getting this error (though I’m trying to build on Windows with 19.52.1) and just wanted to note that the workaround described in #2030 worked for me:

Workaround: please add “extends”: null to build.

Like some people pointed out, react-scripts causes the issue. And according to the documentation, this seems to be expected behavior

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.

It seems to sneak a react-scripts build into the electron-builder command. Interestingly enough, the react-scripts fails for me if run separately, but not when wrapped into the original command. Anyways, you end up with the intransparent "build/electron.js" file does not exist error.

Like the documentation says, disabling extends in the built settings helped for me

package.json

{
  ...
  "build": {
    "extends": null,
    ...
  }
}

Adding path to my electron-starter file in the “file” section worked for me. https://github.com/electron-userland/electron-builder/issues/2955

"build": {
    "appId": "com.example.electron-cra",
    "files": [
      "./build/**/*",
      "./public/electron-starter.js"
    ],
    "directories": {
      "buildResources": "assets"
    }
  },

Simply adding “react-scripts” to the base project will cause this error.

It seems depend on what the main field is set in package.json.

If you are like me and neither of the above solutions work, simply remove the “files” section completely and it’ll start working magically!

FYI,remove the “react-scripts”: “^3.4.0” from dependencies works for me

Simply adding “react-scripts” to the base project will cause this error.

Tried everything… for me solution was just to rename the file itself public/main.js to public/electron.js and as well as updating “main”: “public/electron.js” in package.json

after this update (which means that it wasn’t complaining anymore about not finding electron.js file 🎉) I moved on to another error for the wrong code sign 😩…

Update: Mac gave me issue with Codesign because I have two emails possible solution would be in #2125 But just tested on my Linux and everything worked like a charm after changing the file name to electron.js as I mentioned above.

Cheering you up: I know you are struggling a lot with this, but trust me Keep Gooing It feels so good once you see your built app 😍 and call yourself Genius 😅 Happy coding

@ericblade yeah electron-builder is really powerful but the documentation is super messy. The problem I just faced is that by default, extraMetadata seems to set main to "main.js". Like this:

extraMetadata: {
    "main": "main.js",
  }

… and it overrides the value that is set in your package.json, which is really unexpected.

having similar issue here, but it’s calling the entrypoint “index.js”, which does not correspond to anything in my project, at all. The package.json points to main as “build/main.js”. Inside the asar file, are a small collection of node modules I’ve never heard of, and absolutely nothing else. It’s like builder is just completely ignoring everything inside the configuration it claims it’s loading.

I’m so very confused.

And the documentation is incomprehensible.

try script: build -c.extraMetadata.main=<path/to/electron.js>

Well… have you created this file?

Not sure this will help much, but (in my case) I found that my preelectron-pack was not executing correctly, thus not creating the build folder.

I followed a derived instruction from the mentioned by the OP and found that the build folder wasn’t there.

As I use npm, I changed the line "preelectron-pack": "npm run-script build", and it solved the issue for me.

@patarapolw Thanks a lot. "build/**" not work for me, but "build/**/*" works like a charm

Don’t forget point out main in package.json

"main": "./build/main/index.js",

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"
    }
  }`

I’m getting the exactly same error that @thinkholic mentioned, but on Windows.

The workaround didn’t work.

This problem drove me mad for a while (my server is built into the non default path of build/server/electron.js instead of just build/electron.js). for some reason setting “main” to build/server/electron.js wouldn’t fix this issue, the only thing that worked was as per @mifi additional info.

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

agregar en el pakage.json “files”: [ “build//*", "node_modules//*”, “./public/electron.js” ],

Somehow, setting files work

"build": {
    "files": [
      "dist/**/*",
      "package.json"
    ],
}

@patarapolw It work for we , thanks

I’m getting this error cos I didnt build my cra first.