electron: execFile got Error: spawn EACCES under asar

  • Electron version: v1.6.6, v2.0.8
  • Operating system: 10.12.4 (16E195)

Expected behavior

According to the documentation, Electron asar support execFile

Actual behavior

But I got this error, when I try to use execFile.

Error: spawn EACCES
    at exports._errnoException (util.js:1022:11)
    at ChildProcess.spawn (internal/child_process.js:313:11)
    at exports.spawn (child_process.js:399:9)
    at exports.execFile (child_process.js:160:15)
    at module.(anonymous function) (ELECTRON_ASAR.js:219:18)
    at Object.<anonymous> (/Users/alex/temp/electron-vue/electron-quick-start/dist/mac/electron-quick-start.app/Contents/Resources/app.asar/main.js:16:1)
    at Object.<anonymous> (/Users/alex/temp/electron-vue/electron-quick-start/dist/mac/electron-quick-start.app/Contents/Resources/app.asar/main.js:80:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

How to reproduce

Here is my Code of main.js. I’m using electron-quick-start

const electron = require('electron')
const logger = require('electron-log')
logger.transports.file.level = true;
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

const path = require('path')
const url = require('url')

const execFile = require('child_process').execFile

execFile(path.join(__dirname, 'avrdude', 'avrdude'), (error, stdout, stderr) => {
  if (error) {
    logger.error(error)
  }
  logger.info(stderr)
  logger.info(stdout)
})

I am using electron builder to build a bundle app in macOS. Here is my package.json

{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron .",
    "build": "build"
  },
  "build": {
    "appId": "com.example.demo",
    "files": [
      "avrdude/",
      "node_modules/",
      "package.json",
      "index.html",
      "main.js",
      "renderer.js"
    ]
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "~1.6.2",
    "electron-builder": "^17.5.0"
  },
  "dependencies": {
    "electron-log": "^2.2.6"
  }
}

Here is the asar directory

asar list electron-quick-start.app/Contents/Resources/app.asar
/index.html
/main.js
/package.json
/renderer.js
/node_modules
/node_modules/electron-log
/node_modules/electron-log/LICENSE
/node_modules/electron-log/index.js
/node_modules/electron-log/main.js
/node_modules/electron-log/package.json
/node_modules/electron-log/renderer.js
/node_modules/electron-log/lib
/node_modules/electron-log/lib/format.js
/node_modules/electron-log/lib/log.js
/node_modules/electron-log/lib/transports
/node_modules/electron-log/lib/transports/console.js
/node_modules/electron-log/lib/transports/log-s.js
/node_modules/electron-log/lib/transports/renderer-console.js
/node_modules/electron-log/lib/transports/file
/node_modules/electron-log/lib/transports/file/find-log-path.js
/node_modules/electron-log/lib/transports/file/get-app-name.js
/node_modules/electron-log/lib/transports/file/index.js
/avrdude
/avrdude/avrdude
/avrdude/avrdude.conf

About this issue

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

Most upvoted comments

This happened to me on osx when I tried to run execFile("/Path/App.app").

I then tried execFile("/Path/App.app/Contents/MacOS/App") and that seems to work fine

I am trying to execute a python binary file (created via pyinstaller) through my Electron application on Mac OS. This issue persists in the latest version of Electron (7.1.4). As mentioned above, this problem doesn’t occur on my Windows machine with the same underlying source code. It only happens when I package my Electron application using electron-builder with and without asar. My Electron application is able to run the python binary file when I run the version inside the MacOS folder (MacOS/MyApp). What is the official workaround/fix for this?

Worth noting that I do not encounter this error on windows, but I do in osx. Exact same code.

The Electron version reported on this issue is no longer supported. See our supported versions documentation.

If you’re still experiencing this issue on a supported version, please open a new issue with an updated repro - a Fiddle is very appreciated.

Electron has a large issues backlog. To help our team prioritize, we’re closing older issues and asking for new issues with updated repro steps if it affects a supported version. This helps sort what issues are still relevant and helps us fix them more quickly.

Thanks for your patience and understanding!

Missed that, thanks @tbillington!

@codebytere Don’t know if you saw my comment but I experienced this in electron 2.

Confirming this is still occurring on 6.0.1.

Code to reproduce:

const notes_process: cp.ChildProcess = cp.execFile(
  "/Applications/Notes.app",
  // "/Applications/Notes.app/Contents/MacOS/Notes",
  [],
  (error: Error | null, stdout: string, stderr: string) => {
    console.log(error);
  }
);

Error:

Error: spawn /Applications/Notes.app EACCES
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:9) {
  errno: 'EACCES',
  code: 'EACCES',
  syscall: 'spawn /Applications/Notes.app',
  path: '/Applications/Notes.app',
  spawnargs: [],
  cmd: '/Applications/Notes.app'
}

Switching to the complete path of the binary as opposed to the “.app” path (commented out string in above code) makes the program launch successfully.

I suppose launching with the complete path of the binary is a decent enough workaround for most people?? It works enough for me that I’m not really invested in this issue.

We are no longer implementing bugfixes for versions of Electron <= 1.7.x, so i’m going to close this issue but if it is still persisting in more recent versions of Electron we can certainly reopen it!