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
[kit] resolveAlias should sort keys by length first #14735
[kit] resolveAlias should sort keys by length first #14735
Comments
I believe this is how @rollup/plugin-alias works (which is what Vite uses under the hood). Example: const aliases = {
"#": "./src",
"#components": "./src/components/"
};
// would resolve '#components/foo.vue' to './src/components/foo.vue, correct
// vs
const aliases = {
"#": "./src",
"#components": "./src/deeper/nested/components/"
};
// would resolve '#components/foo.vue' to './src/components/foo.vue, incorrect
// vs
const aliases = {
"#components": "./src/components/",
"#": "./src"
};
// would resolve '#components/foo.vue' to './src/components/foo.vue, correct The example would work in both cases just because the alias is only one level deep, but would cause problems like you're experiencing when having multiple levels. If memory servers me well, TypeScript does the same thing, it probably just iterates through the keys and matches the first. Maybe this should just be noted in the docs? |
@TheDutchCoder this is not a Vite issue - it works as expected when using import aliases in components/composables/etc
Actually no, because Nuxt internally appends custom aliases to own predefined set. // nuxt.options.alias
{
// Nuxt predefined aliases
"~~": "/<rootDir>",
"@@": "/<rootDir>",
"~": "/<rootDir>",
"@": "/<rootDir>",
"assets": "/<rootDir>/assets",
"public": "/<rootDir>/public"
// Any other aliases passed down via nuxt.config.ts
'~components': '/views/components/'
// ... and more
} |
@MorevM Ah fair enough. Maybe prepending them would solve the issue? |
@danielroe this is still an issue in rc.11 Reproduction link: |
Environment
It doesn't matters, but
Windows_NT
v16.15.1
3.0.0-rc.8
yarn@1.22.18
vite
alias
,components
,css
,srcDir
,dir
,telemetry
,modern
,modules
,vite
,nitro
,autoImports
,typescript
Reproduction
Describe the bug
Source of
resolveAlias
functionIt outputs:
root/components/something.vue
Expected output -
root/some/deep/nested/components/something.vue
Additional context
I can make a PR after confirming that this isn't done intentionally
Logs
No response
The text was updated successfully, but these errors were encountered: