question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Yarn 2 link protocol aliases

See original GitHub issue

Clear 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:

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:open
  • Created 2 years ago
  • Reactions:8
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
drazikcommented, Oct 25, 2021

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.

0reactions
merceyzcommented, Nov 11, 2022

From https://github.com/vitejs/vite/issues/2825#issuecomment-812932848 @swandir

NPM does not support “link:”;

While that is true it does support file: which achieves the same thing.

PNPM crashes the install if a “link:”-ed directory does not contain package.json;

This was fixed in pnpm v7.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found