Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
pnpm 10.x reference skill covering workspaces, catalogs, patches, peer deps, overrides, and CI/CD caching strategies.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/features-aliases.md
1---2name: pnpm-aliases3description: Install packages under custom names for versioning, forks, or alternatives4---56# pnpm Aliases78pnpm 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.910## Basic Syntax1112```bash13pnpm add <alias>@npm:<package>@<version>14```1516In `package.json`:17```json18{19"dependencies": {20"<alias>": "npm:<package>@<version>"21}22}23```2425## Use Cases2627### Multiple Versions of Same Package2829Install different versions side by side:3031```json32{33"dependencies": {34"lodash3": "npm:lodash@3",35"lodash4": "npm:lodash@4"36}37}38```3940Usage:41```js42import lodash3 from 'lodash3'43import lodash4 from 'lodash4'44```4546### Replace Package with Fork4748Substitute a package with a fork or alternative:4950```json51{52"dependencies": {53"original-pkg": "npm:my-fork@^1.0.0"54}55}56```5758All imports of `original-pkg` will resolve to `my-fork`.5960### Replace Deprecated Package6162```json63{64"dependencies": {65"request": "npm:@cypress/request@^3.0.0"66}67}68```6970### Scoped to Unscoped (or vice versa)7172```json73{74"dependencies": {75"vue": "npm:@anthropic/vue@^3.0.0",76"@myorg/utils": "npm:lodash@^4.17.21"77}78}79```8081## CLI Usage8283### Add with alias8485```bash86# Add lodash under alias87pnpm add lodash4@npm:lodash@48889# Add fork as original name90pnpm add request@npm:@cypress/request91```9293### Add multiple versions9495```bash96pnpm add react17@npm:react@17 react18@npm:react@1897```9899## With TypeScript100101For type resolution with aliases, you may need to configure TypeScript:102103```json104// tsconfig.json105{106"compilerOptions": {107"paths": {108"lodash3": ["node_modules/lodash3"],109"lodash4": ["node_modules/lodash4"]110}111}112}113```114115Or use `@types` packages with aliases:116117```json118{119"devDependencies": {120"@types/lodash3": "npm:@types/lodash@3",121"@types/lodash4": "npm:@types/lodash@4"122}123}124```125126## Combined with Overrides127128Force all transitive dependencies to use an alias:129130```yaml131# pnpm-workspace.yaml132overrides:133"underscore": "npm:lodash@^4.17.21"134```135136This replaces all `underscore` imports (including in dependencies) with lodash.137138## Git and Local Aliases139140Aliases work with any valid pnpm specifier:141142```json143{144"dependencies": {145"my-fork": "npm:user/repo#commit",146"local-pkg": "file:../local-package"147}148}149```150151## Best Practices1521531. **Clear naming**: Use descriptive alias names that indicate purpose154```json155"lodash-legacy": "npm:lodash@3"156"lodash-modern": "npm:lodash@4"157```1581592. **Document aliases**: Add comments or documentation explaining why aliases exist1601613. **Prefer overrides for global replacement**: If you want to replace a package everywhere, use overrides instead of aliases1621634. **Test thoroughly**: Aliased packages may have subtle differences in behavior164165<!--166Source references:167- https://pnpm.io/aliases168-->169