Skip to content

Fix nodejs.install with npm 12 - #7031

Open
cristianchiriac wants to merge 1 commit into
anomalyco:devfrom
cristianchiriac:fix/npm-12-install-flags
Open

cristianchiriac wants to merge 1 commit into
anomalyco:devfrom
cristianchiriac:fix/npm-12-install-flags

Conversation

@cristianchiriac

Copy link
Copy Markdown

Fixes #6946

npm 12 throws on unknown CLI flags instead of warning (npm/cli#9276). The npm install that nodejs.install runs for a function passed --platform=linux and --arch=x64|arm64, legacy aliases npm no longer knows, so builds fail with:

npm error code EUNKNOWNCONFIG
npm error Unknown cli flags: --platform --arch

The install now passes only --os=linux and --cpu=<x64|arm64>, plus --libc=glibc for sharp as before. Those have selected the target platform since npm 9.9 (npm/cli#6776), so npm 10/11 behave the same. The argument list moved into a small npmInstallArgs(architecture, packages), which also replaces the arm64 patching by slice index (cmd[4], cmd[5]). That patching would have shifted onto the wrong flags once two entries were removed.

Tests:

  • TestNpmInstallArgs in pkg/runtime/node/build_test.go: x86_64, arm64, and arm64 with sharp. It also checks that no --platform / --arch flag is left.
  • go test ./pkg/runtime/node/ and go vet pass. gofmt is clean.
  • Manually, in an empty project with one dependency:
    • npx npm@12.2.0 install --force --platform=linux --os=linux --arch=x64 --cpu=x64 fails with EUNKNOWNCONFIG.
    • npx npm@12.2.0 install --force --os=linux --cpu=x64 installs.
    • So does npm 11.12.1 with --cpu=arm64.

I didn't run a full sst deploy.

npm 12 rejects unknown CLI flags, and --platform/--arch are legacy
aliases it no longer knows, so the install of nodejs.install packages
failed with EUNKNOWNCONFIG. Use only --os/--cpu (npm 9.9+).

Fixes anomalyco#6946
@AlperSakarya

AlperSakarya commented Oct 17, 2026 •

Copy link
Copy Markdown

@cristianchiriac, your change is in the community fork: sst-community/sst#122, released in v4.21.3 (tracked in sst-community/sst#121). Your commit and authorship are kept, with no changes on top.

I checked it on npm 10.9.2, 11.12.1 and 12.2.0. In an empty project the old arguments fail on npm 12 with EUNKNOWNCONFIG and install on the other two, and the new ones install on all three. With --os and --cpu, esbuild gave @esbuild/linux-x64 for x64 and @esbuild/linux-arm64 for arm64 on npm 10 and 12, and sharp with --libc=glibc gave the matching sharp-linux-* and sharp-libvips-linux-* packages.

I also deployed to AWS three functions that use nodejs.install: esbuild on x86_64, esbuild on arm64 and sharp on arm64, and invoked each one. With npm 12 first in PATH, a CLI built from main failed with failed to run npm install: exit status 1, and one built from your change deployed, with the right native packages in each function. With npm 10 and 11 the deploys gave the same result as main.

npm older than 9.9 doesn't select the target architecture with --os and --cpu. On npm 9.2.0 both main and your change installed the x64 packages for the arm64 functions, so the change adds no new floor.

The community fork accepts pull requests, so you are welcome to send them there as well.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nodejs.install fails with npm 12: EUNKNOWNCONFIG on --platform/--arch

2 participants