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

Import aliases stopped working from @marko/vite@4.1.5 onwards #133

Open
vwong opened this issue Apr 28, 2024 · 5 comments
Open

Import aliases stopped working from @marko/vite@4.1.5 onwards #133

vwong opened this issue Apr 28, 2024 · 5 comments

Comments

@vwong
Copy link

vwong commented Apr 28, 2024

Version: 4.1.5 - 4.1.10

I'm trying to use import aliases https://vitejs.dev/config/shared-options#resolve-alias.

This was working fine in @marko/vite@4.1.4 and earlier, but is broken in every version from 4.1.5 onwards.

A minimal reproduction repo is available https://github.com/vwong/marko-vite-bug

@DylanPiercey
Copy link
Contributor

DylanPiercey commented Apr 29, 2024

@vwong FYI the issue isn't that import aliases are not working, it's specifically that ~ doesn't work as an alias anymore since we add a default one here https://github.com/marko-js/vite/blob/main/src/index.ts#L364.

The reason this was added was to (somewhat hackily) improve support with webpack and lasso based apps which for less/css files resolve ~ using the bundlers resolution. Vite doesn't handle ~ in the same way as the others and so we made @marko/vite normalize this for you.

If you change your alias from eg ~ to @ it should work fine.

However I think we could update this alias to be less aggressive, eg /^~(?!\/)/ which would allow your specific remap to slide through.

@DylanPiercey
Copy link
Contributor

DylanPiercey commented Apr 30, 2024

I'll also add that it may make more sense for you to use package json imports for this since it's essentially intended to replace a lot of this aliasing stuff.

Eg

"imports": {
  "#app/*": "./src/*.ts"
}

and then

import "~/thing";
// becomes
import "#app/thing";

@vwong
Copy link
Author

vwong commented Apr 30, 2024

Thanks for the tip. I've can now use package.json imports with @marko/vite@4.1.10.

@vwong
Copy link
Author

vwong commented Apr 30, 2024

Additional tip: Make sure to update tsconfig.json as well.

@DylanPiercey
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants