v3: imports starting with '~/'
Describe the feature
What I like about Nuxt and Nitro v2 is that I can import from root like this:
import { useLogger } from '~/utils/use-logger';
But in v3 I struggle to do so. I tried to add paths to tsconfig.json but then Vite doesnt find the files. Would be cool if Nitro (or create-nitro-app) auto configures tsconfig/Vite so we can import from root by use of ~
If it helps, I have this working using a tsconfig.json file in my root like this:
// SEE https://nitro.unjs.io/guide/typescript
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./server/*"]
},
"allowImportingTsExtensions": true
},
"extends": "./.nitro/types/tsconfig.json",
"exclude": ["node_modules", "**/node_modules/*", "deno.json"]
}
Are you running a Vite project? Because I think there is no more .nitro folder. With the path option it works for my TypeScript / IDE but Vite doesnt catch up the files.
Yeah I think it is Vite, or at least I'm just using the default's of Nitro...
https://github.com/nitrojs/nitro/pull/3757
Example: https://github.com/nitrojs/nitro/tree/main/examples/import-alias
Amazing thanks!! May you release to npm? :)
Shortly :)