Automatic Package Installation (package-auto-install)
Automatic Package Installation (package-auto-install)
Section titled “Automatic Package Installation (package-auto-install)”Automatically detects and runs npm/yarn/pnpm install in non-interactive mode after container creation.
Features
Section titled “Features”- Automatic detection: Detects package manager based on lockfile (pnpm-lock.yaml, yarn.lock, package-lock.json)
- Corepack support: Automatically installs and enables corepack if
packageManagerfield is found in package.json (required for Node 24+) - Non-interactive mode: Sets
CI=trueto avoid prompts (e.g., pnpm won’t ask to delete node_modules) - Smart command selection: Uses
npm ci,pnpm install --frozen-lockfile, oryarn install --immutablewhen lockfiles exist - Flexible configuration: Override package manager, command, and working directory
- Skip if exists: Optionally skip installation if node_modules already exists
Basic Usage
Section titled “Basic Usage”Add this feature to your devcontainer.json:
This will:
- Detect the package manager from lockfile
- Run the appropriate install command automatically
- Set
CI=trueto prevent interactive prompts
Remove Manual postCreateCommand
Section titled “Remove Manual postCreateCommand”If you have this in your devcontainer.json, you can now remove it:
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
command | string | auto | Installation command: install, ci, or auto to detect |
packageManager | string | auto | Package manager: npm, yarn, pnpm, or auto to detect |
workingDirectory | string | /workspaces/${localWorkspaceFolderBasename} | Directory where to run install |
skipIfNodeModulesExists | boolean | false | Skip if node_modules exists |
additionalArgs | string | "" | Additional arguments for install command |
Examples
Section titled “Examples”Force specific package manager
Section titled “Force specific package manager”Use npm ci explicitly
Section titled “Use npm ci explicitly”Skip if node_modules exists (useful for rebuilds)
Section titled “Skip if node_modules exists (useful for rebuilds)”Pass additional arguments
Section titled “Pass additional arguments”Custom working directory
Section titled “Custom working directory”How It Works
Section titled “How It Works”Corepack Support (Node 24+)
If your package.json contains a packageManager field (e.g., "packageManager": "[email protected]"):
- The feature checks if corepack is available
- If not, it installs corepack globally with
npm install -g corepack - Enables corepack with
corepack enable - Corepack then automatically installs and uses the exact package manager version specified
This is particularly important for Node 24+ where corepack is no longer included by default.
Package Manager Detection
Section titled “Package Manager Detection”The feature detects the package manager in this order:
- From
packageManagerfield in package.json (highest priority)- Example:
"packageManager": "[email protected]"→ uses pnpm - This is the most reliable and modern approach
- Example:
- From lockfiles:
pnpm-lock.yaml→ uses pnpmyarn.lock→ uses yarnpackage-lock.json→ uses npm
- Default: Falls back to npm if nothing is detected
Command Selection (when command: "auto")
Section titled “Command Selection (when command: "auto")”For each package manager:
- npm: Uses
npm ciif package-lock.json exists, otherwisenpm install - pnpm: Uses
pnpm install --frozen-lockfileif pnpm-lock.yaml exists, otherwisepnpm install - yarn:
- Yarn 2+: Uses
yarn install --immutableif yarn.lock exists - Yarn 1.x: Uses
yarn install --frozen-lockfileif yarn.lock exists
- Yarn 2+: Uses
CI Mode
Section titled “CI Mode”The feature sets CI=true environment variable, which:
- pnpm: Automatically removes old node_modules without prompting
- npm: Enables strict mode in
npm ci - yarn: Enables immutable installs
Execution Order
Section titled “Execution Order”The feature uses installsAfter to ensure it runs after:
ghcr.io/devcontainers/features/common-utilsghcr.io/devcontainers/features/node
The actual package installation runs in postCreateCommand, which is the last lifecycle hook after all features are installed.
Troubleshooting
Section titled “Troubleshooting”Installation not running
Section titled “Installation not running”Check that:
package.jsonexists in the working directory- The package manager is installed (use node feature or appropriate base image)
Wrong package manager detected
Section titled “Wrong package manager detected”Force the package manager explicitly:
Installation fails
Section titled “Installation fails”Check the container logs during creation. The feature will show the exact command being run and any errors.
Need to debug
Section titled “Need to debug”You can manually run the installation script:
Future Enhancements
Section titled “Future Enhancements”Planned features:
- Support for monorepos (multiple package.json locations)
- Custom post-install scripts
- Conditional installation based on file changes
- Cache optimization
License
Section titled “License”LGPL-3.0 - See LICENSE file for details