Skip to content

On Windows the daemon's latest-version check runs npm's shell wrapper with node and fails at every start #1664

Closed

Description

@V3RON

On Windows the daemon's latest-version check fails at every start:

{"level":"warn","module":"daemon.version-check","message":"Latest Simlock version check failed","fields":{"message":"C:\\Program Files\\nodejs\\npm:3\r\n# This is used by the Node.js installer, which expects the cygwin/mingw\r\n^\r\n\r\nSyntaxError: Invalid or unexpected token\r\n    at wrapSafe (node:internal/modules/cjs/loader:1713:18)\r\n …\r\nNode.js v22.23.5"}}

Seen on Windows 11 23H2 with the official Node 22.23.5 installer, main at c9d82e3.

Why

NodeNpmCli (src/ports/npm-cli.ts:84) runs node on join(dirname(process.execPath), "npm"), which is C:\Program Files\nodejs\npm. On Windows that file is the POSIX shell wrapper the Node installer ships for Cygwin/MinGW, not JavaScript; npm's CLI script is node_modules\npm\bin\npm-cli.js beside it, and the shim to run is npm.cmd. simlock update installs through the same port, so it likely fails the same way.

Expected

The version check (and simlock update's npm call) works on Windows, or the check is skipped there with a clear reason instead of a stack trace every start.

Part of #1068.

Written by an agent.

Activity

  1. added this to the Windows support milestone on Nov 17, 2026
  2. added
    bug:newReported. An agent may triage it (rule 8); the fast track may set it ready (rule 17).
    on Nov 17, 2026
  3. assigned and unassigned on Nov 17, 2026
  4. V3RON commented on Nov 17, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed: a defect. src/ports/npm-cli.test.ts › "runs npm-cli.js from node_modules beside Node when npm there is the installer's shell wrapper" builds the Windows installer's layout (node, the shell wrapper npm, node_modules/npm/bin/npm-cli.js, no symlink) and runs view, install and globalRoot for real. All three fail with the reporter's error, so simlock update is hit too.

    pnpm exec vitest run --project unit src/ports/npm-cli.test.ts
     ❯ src/ports/npm-cli.test.ts:102:22  expect(outcomes).toEqual(...)
    -     "ok": true,
    +     "message": ".../nodejs/npm:3
    + # This is used by the Node.js installer, which expects the cygwin/mingw
    + SyntaxError: Invalid or unexpected token
     Tests  1 failed | 3 passed (4)
    

    I checked on a Windows 11 machine with Node 22.23.5 and read only. C:\Program Files\nodejs holds npm (bash), npm.cmd and node_modules\npm\bin\npm-cli.js. node.exe npm view simlock version fails as above. node.exe node_modules\npm\bin\npm-cli.js view simlock version prints 0.8.0.

    Root cause

    src/ports/npm-cli.ts:84 runs realpath(join(dirname(node), "npm")) as the script. On POSIX installs bin/npm is a symlink to lib/node_modules/npm/bin/npm-cli.js, so realpath finds the JavaScript. The Windows installer has no symlink there, and npm beside node.exe is a bash wrapper, so node parses bash as JavaScript. The daemon's version check (src/daemon/main.ts:311) and the updater (src/updater/main.ts:25) both build this port, so the symptom shows in both.

    Simplest fix

    In NodeNpmCli.#run, use join(dirname(node), "node_modules", "npm", "bin", "npm-cli.js") when filesystem.exists says it is there. Otherwise keep today's realpath of npm. No platform switch is needed, and no cmd.exe is involved.

    fix applied, then: pnpm exec vitest run --project unit src/ports/npm-cli.test.ts src/ports/filesystem.test.ts \
      src/updater/index.test.ts src/daemon/main-update.test.ts src/daemon/server-update.test.ts src/daemon/server-startup.test.ts
     Test Files  6 passed (6)   Tests  124 passed (124)
    

    Alternatives rejected

    • Run npm.cmd: it needs cmd.exe and the %/" argument limits of windows-command.ts, for no gain.
    • Branch on process.platform === "win32": it needs a new option, and a Mac test could not drive it without one. The layout check covers the same installs.
    • Skip the check on Windows: npm works there, and simlock update would stay broken.

    Risk

    • On Windows, npm i -g npm installs into %APPDATA%\npm, but simlock keeps running the npm bundled with Node. That npm still works.
    • Check that no POSIX install puts a node_modules/npm folder in Node's bin directory (Homebrew, nvm, the official .pkg).

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  5. removed their assignment
    on Nov 17, 2026
  6. added
    bug:readyAn agent may fix it.
    fast-trackBug set ready by the fast-track check, not the maintainer (rule 17).
    and removed
    bug:newReported. An agent may triage it (rule 8); the fast track may set it ready (rule 17).
    on Nov 17, 2026
  7. self-assigned this
    on Nov 17, 2026
  8. V3RON commented on Nov 17, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1673 (#1664)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

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

Metadata

Metadata

Assignees

Labels

bug:readyAn agent may fix it.fast-trackBug set ready by the fast-track check, not the maintainer (rule 17).

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions