npm 12: installer passes removed --unsafe-perm flag, install fails with EUNKNOWNCONFIG · Issue #7950 · coder/code-server · GitHub
Skip to content

npm 12: installer passes removed --unsafe-perm flag, install fails with EUNKNOWNCONFIG #7950

Description

@hermes-selfhost-bot

Bug: npm install -g code-server fails on npm 12 with "Unknown cli flag: --unsafe-perm"

code-server's installer passes --unsafe-perm to npm, but npm 12 removed that flag and now errors on any unknown flag instead of ignoring it. Result: the install dies before it even starts.

How to reproduce (2 commands, ~45 seconds)

npm --version   # must be 12.x (Node 22+ ships npm 11+; install npm@12 first if needed)
npm install -g code-server@4.117.0 --unsafe-perm

Expected: code-server installs.
Actual:

npm error code EUNKNOWNCONFIG
npm error Unknown cli flag:
npm error   - --unsafe-perm
npm error Run `npm help config` for supported options.

That's it. No code-server source needed — the failure is npm rejecting the flag that install.sh passes.

Where the flag lives

Three active places pass or require --unsafe-perm:

  • install.sh line 439 — npm install ... --unsafe-perm
  • ci/build/npm-postinstall.sh lines 79–92 — root-only npm_config_unsafe_perm guard
  • ci/build/npm-postinstall.sh lines 111–116 — nested npm install --unsafe-perm

Why it's safe to remove

npm stopped needing --unsafe-perm in npm 7 — when npm runs as root, lifecycle scripts already run with the effective UID/GID of the package directory owner. The flag has been a no-op for years; npm 12 just finally made passing it an error. See npm's changelog: https://docs.npmjs.com/cli/v7/using-npm/changelog/#root-user-does-not-drop-privileges

Environment

  • Node.js 22.22.2, npm 12.0.2
  • code-server 4.117.0 (install fails before running)
  • Debian 13

Bonus caveat (read before saying "just remove it")

With --unsafe-perm gone, npm 12's new lifecycle-script policy also blocks code-server's postinstall by default:

npm warn install-scripts 2 packages had install scripts blocked...
npm warn install-scripts   code-server@4.117.0 (postinstall: sh ./postinstall.sh)
npm warn install-scripts   argon2@0.44.0 (install: ...)

So removing the flag fixes the crash, but full npm 12 support also needs the --allow-scripts=code-server,argon2 (or equivalent) handling. I have a test-backed patch for the --unsafe-perm part (36/36 script tests pass) — happy to open a PR if this is accepted.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcode-serverneeds-investigationThis issue needs to be further investigated

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions