Set ts config paths from `aliases` config
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Describe the feature
Context
In the past I used Nuxt extensively, now I am also using Nitro by itself to build a standalone server. The Nuxt/Nitro configs are quite similar. The defineNitroConfig takes an input with type NitroConfig which extends NitroOptions. We have the option to set an alias which is described in the docs here. For Nuxt there is a similar option but the docs are different though.
Goal
My expectation would be that the configs work in the same way. I should be able to put aliases in the Nitro config and they are put to the .nitro/types/tsconfig.json under compilerOptions.paths like Nuxt does.
Findings
I found out that I can achieve the desired behaviour by setting both alias and tsConfig.compilerOptions. Example:
export default defineNitroConfig({
alias: {
foo: fileURLToPath(new URL('../bar', import.meta.url)),
},
typescript: {
tsConfig: {
compilerOptions: {
paths: {
foo: [fileURLToPath(new URL('../bar', import.meta.url))],
},
},
},
},
});
At least I hope that this recreates the same behaviour, first tests look good. In Nuxt it is not necessary to also set the typescript.tsConfig part.
Solution
In the perfect world both configs behave the same way. I cannot really assess which implications a change of the Nitro config has. Can we connect alias/typescript settings? For me also an extension/adjustment of the Nitro docs would be ok, since I needed quite some time and digging to figure out how to configure Nitro correctly (assuming the finding above is correct). Anyways I would be open to contribute/suggest a change.
Related
Additional information
- Would you be willing to help implement this feature?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Nitro's alias and typescript.tsConfig settings, then inspect the generated .nitro/types/tsconfig.json and compare the expected behavior with Nuxt's alias configuration. Review the related Nuxt issue and Nitro pull request #1266 for prior context. Done means aliases consistently populate compilerOptions.paths without requiring duplicate configuration, with documentation clarified if needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- backend, build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100