Skip to content

npm

Version: 1.0.0 | Tests: Passing

devcontainer.json
{
    "features": {
        "ghcr.io/infrashift/trusted-devcontainer-features/npm:latest": {
            "target_version": "11.4.1"
        }
    }
}
OptionTypeDefaultDescription
target_versionstring11.4.1Select the npm version to install
nodejsthis feature

This feature updates npm to a specific version using npm install -g npm@<version>. Rather than downloading a standalone binary, it leverages the npm self-upgrade mechanism to replace the bundled version that ships with Node.js.

The Ansible playbook runs the upgrade command after Node.js is installed, which is guaranteed by the nodejs feature dependency. When you include the npm feature in your devcontainer configuration, the dependency chain ensures that Node.js is set up first, and then npm is upgraded to the version specified in the target_version option.

This is useful when you need a newer npm version than what ships with the installed Node.js release, or when your project requires a specific npm version for reproducible lockfile behavior. By splitting Node.js and npm into separate features, you can pin each version independently without being locked to whatever npm version a particular Node.js release bundles.