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
Have you tried something like that?
Nope, I was following the docs and using <rootDir>
This is the alias config property correct?
Will give it a try!
it's
typescript.tsConfig.compilerOptions.paths
in the nuxt.config.ts
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
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
Thanks for the reply! Will see if I find some more info or someone has some inside on it!
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:
I tried what @Fabian B. said and did not work unfortunately 😦
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 ?