Skip to content

Add support for configuring npm version in Node devcontainers#1616

Open
sireeshajonnalagadda wants to merge 12 commits intodevcontainers:mainfrom
sireeshajonnalagadda:npm-version
Open

Add support for configuring npm version in Node devcontainers#1616
sireeshajonnalagadda wants to merge 12 commits intodevcontainers:mainfrom
sireeshajonnalagadda:npm-version

Conversation

@sireeshajonnalagadda
Copy link
Copy Markdown
Contributor

@sireeshajonnalagadda sireeshajonnalagadda commented Apr 7, 2026

Context:
When using the Node feature in devcontainers, npm is installed globally but always defaults to the bundled version. This often leads to noisy update prompts when running npm commands, and any manual updates are lost after rebuilding the container.

Problem:

Developers frequently need to pin a specific npm version globally.

Current workaround requires adding an onCreateCommand in devcontainer.json to run npm install -g npm@.

This is repetitive and not baked into the image.

Solution (Implemented in this PR):

Added support for specifying npmVersion alongside version in the Node feature configuration.

Example usage:

json
"ghcr.io/devcontainers/features/node:1": {
"version": "24",
"npmVersion": "11.11.1"
}
Ensures npm version is installed globally during container build, avoiding update prompts and rebuild inconsistencies.

Changes made:

  • Adds a new npmVersion option to the Node devcontainer feature so users can pin npm (or set it to latest / none) directly in devcontainer.json.

  • Updates the Node feature install script to install/upgrade npm globally during build, including skip logic (none), retries, proxy handling, and a compatibility fallback when the requested npm version doesn’t match the Node version.

  • Adds/updates tests and scenarios to cover installing a specific npm version, skipping npm updates, upgrading to latest, and an incompatible “latest npm + Node 16” case.

Outcome:
Developers can now configure both Node and npm versions directly in their devcontainer setup, improving reproducibility and reducing noise from npm update prompts.

@sireeshajonnalagadda sireeshajonnalagadda changed the title feat(node): add npm version selection and installation options Add support for configuring npm version in Node devcontainers Apr 7, 2026
@Kaniska244 Kaniska244 requested a review from Copilot April 13, 2026 12:30
@Kaniska244 Kaniska244 marked this pull request as ready for review April 13, 2026 12:31
@Kaniska244 Kaniska244 requested a review from a team as a code owner April 13, 2026 12:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an npmVersion configuration option to the Node devcontainer feature so users can pin/upgrade (or skip updating) the globally available npm version during image build, and adds scenario coverage for the new behavior.

Changes:

  • Introduces npmVersion option in the Node feature metadata.
  • Updates the Node feature install script to optionally install/upgrade npm with compatibility fallback and retries.
  • Adds new test scenarios/scripts for specific npm, latest npm, skipping npm updates, and an incompatibility case.
Show a summary per file
File Description
test/node/scenarios.json Adds new scenarios to exercise npmVersion behaviors.
test/node/install_specific_npm_version.sh Verifies pinning npm to a specific version.
test/node/install_npm_none.sh Adds a “skip npm update” scenario (currently minimal assertion).
test/node/install_npm_latest.sh Verifies upgrading npm when npmVersion=latest (and pnpm still works).
test/node/install_npm_latest_incompatible.sh Adds an incompatibility scenario (currently missing an active assertion).
src/node/install.sh Implements npm install/upgrade logic, compatibility checks, and retries.
src/node/devcontainer-feature.json Adds the npmVersion option and proposals/default.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 7/7 changed files
  • Comments generated: 6

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.

2 participants