Add support for configuring npm version in Node devcontainers#1616
Draft
sireeshajonnalagadda wants to merge 5 commits intodevcontainers:mainfrom
Draft
Add support for configuring npm version in Node devcontainers#1616sireeshajonnalagadda wants to merge 5 commits intodevcontainers:mainfrom
sireeshajonnalagadda wants to merge 5 commits intodevcontainers:mainfrom
Conversation
…llback for incompatible Node.js versions
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.