#possible to do path alias in convex/tsconfig?
16 messages · Page 1 of 1 (latest)
Are you intentionally setting ~/ to repo root or /convex ? I use it as an alias for root and it works:
"paths": {
"~/*": ["../*"],
}
Hmm yeah I'm seeing the same, that's weird. "../convex/*" also doesn't work.
yea just curious. no big deal tho, life's good with relative path too 😂
I use what I pasted above, so convex root is ~/convex/ - still better than relative.
No problem!
One thing that causes trouble is when there is a disconnect between the convex/tsconfig.json and the tsconfig.json you have in your frontend folder. Not an expert, but if others have trouble that's worth playing with
@placid flare I just realized the errors I was seeing were from eslint, typescript was actually resolving fine. Any chance that was the case for you? My error was from import/no-unresolved specifically.
The fix for eslint is to add the paths to both your base tsconfig and your convex tsconfig to eslint config:
'settings': {
'import/resolver': {
typescript: {
project: ['convex/tsconfig.json', 'tsconfig.json'],
},
}
Docs: https://github.com/import-js/eslint-import-resolver-typescript?tab=readme-ov-file#configuration
oh wow interesting, thanks! i've never installed the pkg above
Following up in case anyone else comes across this post - this did not actually work out.
As far as I can tell, with nested typescript configs, the base config will need you to treat path aliases as a global set. I had to go with @cvx/ for relative base path in convex folder as @/ is already pointing at /src. You'll want to list all aliases in a tsconfig if the alias is in the tsconfig directory or any root, which means duplicating those in nested tsconfigs.
@inner pike Is it not possible to just extend the root tsconfig using the extends option (https://www.typescriptlang.org/tsconfig/#extends), so that the whole project uses the same tsconfig, and only specify the options required by Convex in convex/tsconfig as in:
{
/* This TypeScript project config describes the environment that
* Convex functions run in and is used to typecheck them.
* You can modify it, but some settings required to use Convex.
*/
"compilerOptions": {
/* Extend the base config at the root of the project to avoid double maintenance */
"extends": "../tsconfig.json",
/* These compiler options are required by Convex */
"target": "ESNext",
"lib": ["ES2021", "dom"],
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"isolatedModules": true,
"noEmit": true
},
"include": ["./**/*"],
"exclude": ["./_generated"]
}
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Did this work for you? I agree that approach looks cleaner