Add support for configuring npm version in Node devcontainers#1616
Open
sireeshajonnalagadda wants to merge 12 commits intodevcontainers:mainfrom
Open
Add support for configuring npm version in Node devcontainers#1616sireeshajonnalagadda wants to merge 12 commits intodevcontainers:mainfrom
sireeshajonnalagadda wants to merge 12 commits intodevcontainers:mainfrom
Conversation
…llback for incompatible Node.js versions
Contributor
There was a problem hiding this comment.
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
npmVersionoption 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
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.