Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias is handled before attemptnig to find the module, breaking any usages with @ alias #450

Open
xsjcTony opened this issue Dec 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@xsjcTony
Copy link

xsjcTony commented Dec 3, 2024

Environment

unbuild: v3.0.0-rc.11
Node.js: v20.18.1

Reproduction

https://github.com/xsjcTony/unocss-preset-animations
If unbuild's version is upgraded to v3.0.0-rc.2 or greater, externals won't work as expected due to this issue.

Describe the bug

Because of the implementation here https://github.com/unjs/unbuild/blob/main/src/builders/rollup/utils.ts#L44-L54 simply replace all alias keys, normal usages like @ will break.

E.g. when I'm trying to alias my root as @, then I'll have something like

import { foo } from '@/bar'

But I can also have something like

import { definePreset } from '@unocss/core`

This will break straight away with setting

alias: {
  '@': fileURLToPath(new URL('src', import.meta.url))
}

Resulting in something like

// Original
@unocss/core
// After replacing
C:\Dev\personal-projects\unocss-preset-animations\srcunocss/core

Hence even if I set @unocss/core in externals, it will still be inlined.


Solution:

I think it should attempt to find the module first, before parsing alias, giving it a chance to find the correct package straight away.

Additional context

😂Every package start with @ just breaks
@jridgewell/sourcemap-codec
->
C:\Dev\personal-projects\unocss-preset-animations\srcjridgewell/sourcemap-codec

Logs

No response

@xsjcTony xsjcTony added the bug Something isn't working label Dec 3, 2024
@xsjcTony xsjcTony changed the title alias is handled before attemptnig to find the module alias is handled before attemptnig to find the module, breaking any usages with @ alias Dec 3, 2024
@pi0
Copy link
Member

pi0 commented Dec 28, 2024

We should fix the alias issue but there will be always issues with @ aliases. ~ is much safer option I suggest also you can use @/ or @[id] aliases which are more explicit and won't conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants