Skip to content

[Bug] 2.37 dev branch,. fails on electronSwitches #4159

Closed

Description

@sdetweil

Environment

System Information

  • SYSTEM: manufacturer: System manufacturer; model: System Product Name; virtual: false; MM: v2.37.0-develop
  • OS: platform: linux; distro: Ubuntu; release: 22.04.5 LTS; arch: x64; kernel: 5.15.0-177-generic
  • VERSIONS: electron: 42.1.0; used node: 24.15.0; installed node: 22.22.1; npm: 10.9.4; pm2: 5.4.3
  • ENV: XDG_SESSION_TYPE: x11; MM_CONFIG_FILE: undefined
    WAYLAND_DISPLAY: undefined; DISPLAY: :0.0; ELECTRON_ENABLE_GPU: undefined
  • RAM: total: 48076.70 MB; free: 40129.30 MB; used: 7947.40 MB
  • OTHERS: uptime: 11076 minutes; timeZone: America/Chicago
    [2026-05-18 14:18:58.875] [LOG] [electron] Launching applic

Which start option are you using?

node --run start:x11

Are you using PM2?

No

Module

None

Have you tried disabling other modules?

  • Yes
  • No

Have you searched if someone else has already reported the issue on the forum or in the issues?

  • Yes

What did you do?

Configuration
    electronSwitches: {
      "password-store": "basic",
      "js-flags": "--max-old-space-size=8192"
    },
<!-- Paste relevant code here -->

Steps to reproduce the issue:

What did you expect to happen?

has been working for 'years' (or maybe not working)

What actually happened?

I added the console.log elsw...

[2026-05-18 14:18:58.876] [LOG]   [electron] elsw { 'password-store': 'basic', 'js-flags': '--max-old-space-size=8192' }
[2026-05-18 14:18:58.877] [ERROR] [unknown] (node:725432) UnhandledPromiseRejectionWarning: TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))
    at createWindow (/home/sam/MagicMirror.2.36.dev/js/electron.js:49:39)

config.js

    electronSwitches: {
      "password-store": "basic",
      "js-flags": "--max-old-space-size=8192"
    },

from the electron doc , SOME switches are keyword/value

app.commandLine.appendSwitch('remote-debugging-port', '8315')
app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1')

so the config value cannot be flat array of single values.. ,, I think appendswitch of {'remote-debugging-port': '8315'} , would fail too

i'm guessing the old code didn't work either

        let electronSwitchesDefaults = ["autoplay-policy", "no-user-gesture-required"];
        app.commandLine.appendSwitch(...new Set(electronSwitchesDefaults, config.electronSwitches));

at least, the defaults were connected , "autoplay-policy":"no-user-gesture-required"

changing my switches to

    electronSwitches: [
      {"password-store": "basic"},
      {"js-flags": "--max-old-space-size=8192"}
    ],

doesn't produce an error on startup, but I don't know if the switches are correctly passed..

Additional comments

No response

Participation

  • I am willing to submit a pull request for this change.

Activity

  1. KristjanESPERANTO commented on May 18, 2026

    @KristjanESPERANTO
    Collaborator

    Thanks Sam - yes, this is a real issue.

    electronSwitches was broken since PR #2643 (the new Set(...) swallowed the user config). #4136 only got it working like the way the docs claimed - array of strings - but as you point out, that design can't express switches with values, since Electron wants appendSwitch(name, value).

    I think the cleanest fix is to just switch to an object. I'll take a look in the next days.

  2. sdetweil commented on May 18, 2026

    @sdetweil
    CollaboratorAuthor

    I didn't see any electron examples of plain switch --foobar

    but this heading lists some..
    https://www.electronjs.org/docs/latest/api/command-line-switches#electron-cli-flags

    does appendSwitch have an override for no value for the switch? or are these ONLY allowed on the commandline??

    whats the difference between a switch and a flag? if they both can be done on the cli???

  3. KristjanESPERANTO commented on May 19, 2026

    @KristjanESPERANTO
    Collaborator

    I checked this locally with Electron.

    appendSwitch does seem to support both forms:

    app.commandLine.appendSwitch("no-sandbox");
    app.commandLine.appendSwitch("js-flags", "--max-old-space-size=8192");

    That gives me:

    {"noSandbox":true,"jsFlags":"--max-old-space-size=8192"}

    I also checked whether passing name=value as a single string would work:

    app.commandLine.appendSwitch("js-flags=--max-old-space-size=8192");

    That does not register js-flags; it registers the whole string as the switch name. So the current array-of-strings design really can't express switches with values.

    On "switch" vs "flag": I'm not sure there is a strict distinction here. Electron seems to use both terms for command-line args like --name or --name=value.

    So I still think an object form maps best to Electron's API:

    electronSwitches: {
        "no-sandbox": true,
        "js-flags": "--max-old-space-size=8192"
    }

    I'll try to look into this soon more deeply and open a PR if it works out. Unless someone else wants to take a shot at it first :)

  4. sdetweil commented on May 19, 2026

    @sdetweil
    CollaboratorAuthor

    I don’t like this but, js arrays support dissimilar things

    [
    "no-sandbox”,
    { "js-flags": "--max-old-space-size=8192"}
    ]
    And it’ll be a pain to support in mmm-config

    So if the array element is a string,
    Then use the single form append
    Else if object not array,
    use the dual form, object_key, object_value
    Else error

    Then you dont have any ambiguity over the object value fake ‘true’ in

    "no-sandbox": true,
    
  5. KristjanESPERANTO commented on May 19, 2026

    @KristjanESPERANTO
    Collaborator

    Okay, keeping the array is also a good choice. I've created #4161 :)

  6. added a commit that references this issue on May 20, 2026
    e55b11b
  7. changed the title [-][Bug] 37 dev branch,. fails on electronSwitches[/-] [+][Bug] 2.37 dev branch,. fails on electronSwitches[/+] on May 21, 2026
  8. sdetweil commented on Jun 5, 2026

    @sdetweil
    CollaboratorAuthor

    one thing, should we update js/defaults.js to add the electronSwitches variable?
    are there others missing too, I can't keep up!

  9. KristjanESPERANTO commented on Jun 6, 2026

    @KristjanESPERANTO
    Collaborator

    Good point. For the behavior it doesn't matter, but for clarity and consistency, it makes perfect sense to add the defaults. I've created #4181 to handle this :)

    I'll also work on the relevant docs later - I noticed a few issues while preparing the PR.

  10. added a commit that references this issue on Jun 6, 2026
  11. KristjanESPERANTO commented on Jun 6, 2026

    @KristjanESPERANTO
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions