Support Yarn 2 link protocol aliases
See original GitHub issueClear and concise description of the problem
Yarn 2 offers the link protocol as a tool-agnostic way to configure aliases: https://yarnpkg.com/features/protocols/#why-is-the-link-protocol-recommended-over-aliases-for-path-mapping
{
"dependencies": {
"src": "link:./src"
}
}
The problem is that Vite tries to pre-bundle the linked directory as a dependency
error when starting dev server:
Error: The following dependencies are imported but could not be resolved:
src/<path> (imported by <path>)
Suggested solution
Vite could recognize this pattern by either:
- detecting that the linked folder is within the project root;
- not attempting to pre-bundle “link:” dependencies altogether as they are not treated as packages by yarn.
Alternative
As a work-around this works:
export default defineConfig({
optimizeDeps: {
exclude: ["src"],
},
});
UPDATE: it doesn’t work. But resolve.alias
can be used instead.
But it’d be nicer to have this handled automatically.
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Protocols | Yarn - Package Manager
Why is the link: protocol recommended over aliases for path mapping? Many tools support a feature generally known as "aliases", which allows you...
Read more >Configure aliases once and for all with Yarn's link protocol
A journey from configuring aliases in multiple times for multiple tools to one time at the package manager level.
Read more >Configure aliases once and for all with Yarn's link protocol
Configure aliases once and for all with Yarn's link protocol. r/javascript - Configure aliases ... help configuring VLANs and second NIC. 2.
Read more >Maël on Twitter: "25 ☝️ Prefer using the `portal:` or `link ...
18 It also supports positional arguments (`$1`, `$2`, …), including `$@`! ... yarnpkg.com. Protocols. An in-depth guide to Yarn's various protocols. 2.
Read more >Configure aliases once and for all with Yarn's link protocol
Configure aliases once and for all with Yarn's link protocol ... Appwrite - The Open Source Firebase alternative introduces iOS support ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is anything planned to fix this? It would be awesome if Vite worked with this Yarn feature. It makes alias tool-agnostic. Currently I have it enabled and working for multiple tools, but it fails in Vite, so I have to manually duplicate aliases in
vite.config.ts
.I would be happy to help if possible, but I am a newcomer so I will need help entering Vite’s codebase I think.
From https://github.com/vitejs/vite/issues/2825#issuecomment-812932848 @swandir
While that is true it does support
file:
which achieves the same thing.This was fixed in pnpm v7.