PageSourceSearch

https://pnpm.io/assets/js/5a566e4b.1cc619ef.js

js pnpm.io collected 2026-09-24 07:23:37 UTC 4,070 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([["23142"],{9534(e,n,s){s.r(n),s.d(n,{metadata:()=>o,default:()=>h,frontMatter:()=>l,contentTitle:()=>t,toc:()=>r,assets:()=>d});var o=JSON.parse('{"id":"aliases","title":"Aliases","description":"Aliases let you install packages with custom names.","source":"@site/versioned_docs/version-10.x/aliases.md","sourceDirName":".","slug":"/aliases","permalink":"/10.x/aliases","draft":false,"unlisted":false,"editUrl":"https://github.com/pnpm/pnpm.io/edit/main/versioned_docs/version-10.x/aliases.md","tags":[],"version":"10.x","lastUpdatedBy":"Zoltan Kochan","lastUpdatedAt":1771892155000,"frontMatter":{"id":"aliases","title":"Aliases"},"sidebar":"docs","previous":{"title":"Config Dependencies","permalink":"/10.x/config-dependencies"},"next":{"title":"Command line tab-completion","permalink":"/10.x/completion"}}'),a=s(91987),i=s(67008);let l={id:"aliases",title:"Aliases"},t,d={},r=[];function c(e){let n={code:"code",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"Aliases let you install packages with custom names."}),"\n",(0,a.jsxs)(n.p,{children:["Let's assume you use ",(0,a.jsx)(n.code,{children:"lodash"})," all over your project. There is a bug in ",(0,a.jsx)(n.code,{children:"lodash"}),"\nthat breaks your project. You have a fix but ",(0,a.jsx)(n.code,{children:"lodash"})," won't merge it. Normally\nyou would either install ",(0,a.jsx)(n.code,{children:"lodash"})," from your fork directly (as a git-hosted\ndependency) or publish it with a different name. If you use the second solution\nyou have to replace all the requires in your project with the new dependency\nname (",(0,a.jsx)(n.code,{children:"require('lodash')"})," => ",(0,a.jsx)(n.code,{children:"require('awesome-lodash')"}),"). With aliases, you\nhave a third option."]}),"\n",(0,a.jsxs)(n.p,{children:["Publish a new package called ",(0,a.jsx)(n.code,{children:"awesome-lodash"})," and install it using ",(0,a.jsx)(n.code,{children:"lodash"})," as\nits alias:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{children:"pnpm add lodash@npm:awesome-lodash\n"})}),"\n",(0,a.jsxs)(n.p,{children:["No changes in code are needed. All the requires of ",(0,a.jsx)(n.code,{children:"lodash"})," will now resolve to\n",(0,a.jsx)(n.code,{children:"awesome-lodash"}),"."]}),"\n",(0,a.jsx)(n.p,{children:"Sometimes you'll want to use two different versions of a package in your\nproject. Easy:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-sh",children:"pnpm add lodash1@npm:lodash@1\npnpm add lodash2@npm:lodash@2\n"})}),"\n",(0,a.jsxs)(n.p,{children:["Now you can require the first version of lodash via ",(0,a.jsx)(n.code,{children:"require('lodash1')"})," and the\nsecond via ",(0,a.jsx)(n.code,{children:"require('lodash2')"}),"."]}),"\n",(0,a.jsxs)(n.p,{children:["This gets even more powerful when combined with hooks. Maybe you want to replace\n",(0,a.jsx)(n.code,{children:"lodash"})," with ",(0,a.jsx)(n.code,{children:"awesome-lodash"})," in all the packages in ",(0,a.jsx)(n.code,{children:"node_modules"}),". You can\neasily achieve that with the following ",(0,a.jsx)(n.code,{children:".pnpmfile.cjs"}),":"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-js",children:"function readPackage(pkg) {\n  if (pkg.dependencies && pkg.dependencies.lodash) {\n    pkg.dependencies.lodash = 'npm:awesome-lodash@^1.0.0'\n  }\n  return pkg\n}\n\nmodule.exports = {\n  hooks: {\n    readPackage\n  }\n}\n"})})]})}function h(e={}){let{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},67008(e,n,s){s.d(n,{R:()=>l,x:()=>t});var o=s(71763);let a={},i=o.createContext(a);function l(e){let n=o.useContext(i);return o.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function t(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.