Import alias are not working for folders outside sourceDir

Hello everyone!! I have some issues while importing files out of the sourceDir with an alias in Nuxt 3. I am at the phone, so I will try to make the best reproduction of what I have. Imagine you have a folder like this: /nuxt-project/modules/some-module.js /common-utils/foo.js Now I would like to create an alias import like: import something from '@alias/foo.js'. I tried defining it on nuxt.config.ts but without any results. Importing the file with relative paths work fine tho!
8 Replies
Fabian B.
Fabian B.2y ago
Have you tried something like that?
No description
> Rodrigo
> Rodrigo2y ago
Nope, I was following the docs and using <rootDir> This is the alias config property correct? Will give it a try!
Fabian B.
Fabian B.2y ago
it's typescript.tsConfig.compilerOptions.paths in the nuxt.config.ts
> Rodrigo
> Rodrigo2y ago
Im using normal js for those imports, not typescript (for now, its a migration) does that still aplly? Do I need to define paths for both javascript and typescript? Thanks a lot for the help btw! I tried solving this for 4 or 5h by now
Fabian B.
Fabian B.2y ago
Oh okay no then that’s a whole different topic Never used nuxt 3 with non-ts imports, so maybe someone else has experience on this? But I guess before to waste too much time use direct imports without an alias
> Rodrigo
> Rodrigo2y ago
Thanks for the reply! Will see if I find some more info or someone has some inside on it!
> Rodrigo
> Rodrigo2y ago
Got some more visualization for the problem: nuxt-project/modules/logger.js is the attached image. And I would like to import that file that lives inside 'common/' that is an adjacent dir to nuxt-project. My nuxt-config:
alias: {
'@something/common': path.resolve(__dirname, '../common')
},
vite: {
resolve: {
alias: {
'@something/common': path.resolve(__dirname, '../common')
}
},
},
alias: {
'@something/common': path.resolve(__dirname, '../common')
},
vite: {
resolve: {
alias: {
'@something/common': path.resolve(__dirname, '../common')
}
},
},
I tried what @Fabian B. said and did not work unfortunately 😦
No description
Julien
Julien2y ago
Hi when installing a module, nuxt use jiti to import it and does not pass any alias arguments to it. This might be the reason it crashes. @Fabian B. what do you think ?
Want results from more Discord servers?
Add your server