possible to do path alias in convex/tsconfig?
hello team. is it possible to add an alias for the path in convex/tsconfig? i tried adding the following and things started to break. using the relative path works. thanks!
14 Replies
Are you intentionally setting
~/
to repo root or /convex
? I use it as an alias for root and it works:
yea, i intentionally want it for /convex
root works for me too
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.oh u r right!!! good idea 🙂
thanks!!
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
@winsoroaks 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:
Docs: https://github.com/import-js/eslint-import-resolver-typescript?tab=readme-ov-file#configurationoh 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.@erquhart 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:
TSConfig Reference - Docs on every TSConfig option
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
I didn't try it. I haven't worked with Convex in a while