.agents/skills/pnpm/references/features-aliases.md
pnpm supports package aliases using the npm: protocol. This lets you install packages under different names, use multiple versions of the same package, or substitute packages.
pnpm add <alias>@npm:<package>@<version>
In package.json:
{
"dependencies": {
"<alias>": "npm:<package>@<version>"
}
}
Install different versions side by side:
{
"dependencies": {
"lodash3": "npm:lodash@3",
"lodash4": "npm:lodash@4"
}
}
Usage:
import lodash3 from 'lodash3'
import lodash4 from 'lodash4'
Substitute a package with a fork or alternative:
{
"dependencies": {
"original-pkg": "npm:my-fork@^1.0.0"
}
}
All imports of original-pkg will resolve to my-fork.
{
"dependencies": {
"request": "npm:@cypress/request@^3.0.0"
}
}
{
"dependencies": {
"vue": "npm:@anthropic/vue@^3.0.0",
"@myorg/utils": "npm:lodash@^4.17.21"
}
}
# Add lodash under alias
pnpm add lodash4@npm:lodash@4
# Add fork as original name
pnpm add request@npm:@cypress/request
pnpm add react17@npm:react@17 react18@npm:react@18
For type resolution with aliases, you may need to configure TypeScript:
// tsconfig.json
{
"compilerOptions": {
"paths": {
"lodash3": ["node_modules/lodash3"],
"lodash4": ["node_modules/lodash4"]
}
}
}
Or use @types packages with aliases:
{
"devDependencies": {
"@types/lodash3": "npm:@types/lodash@3",
"@types/lodash4": "npm:@types/lodash@4"
}
}
Force all transitive dependencies to use an alias:
# pnpm-workspace.yaml
overrides:
'underscore': 'npm:lodash@^4.17.21'
This replaces all underscore imports (including in dependencies) with lodash.
Aliases work with any valid pnpm specifier:
{
"dependencies": {
"my-fork": "npm:user/repo#commit",
"local-pkg": "file:../local-package"
}
}
Clear naming: Use descriptive alias names that indicate purpose
"lodash-legacy": "npm:lodash@3"
"lodash-modern": "npm:lodash@4"
Document aliases: Add comments or documentation explaining why aliases exist
Prefer overrides for global replacement: If you want to replace a package everywhere, use overrides instead of aliases
Test thoroughly: Aliased packages may have subtle differences in behavior