Accessing env variables + TS errors
When trying to access an environment variable in a Convex action (per https://docs.convex.dev/using/environment-variables#accessing-environment-variables), TypeScript complains that it doesn't know what
process
is:
Cannot find name 'process'. Do you need to install type definitions for node? Try npm i --save-dev @types/node
and then add 'node' to the types field in your tsconfig. (tsserver 2591)
I see in Convex's tsconfig.json
the following:
Any thoughts on what I ought to do here? I'd think everyone would encounter this when trying to use environment variables in their Convex actions, unless the Convex-generated tsconfig.json
file has changed its contents since I last generated it 🤔7 Replies
I believe the Convex-generated tsconfig.json has changed!
I believe there's now a single
tsconfig.json
for the entire Convex directory with that types: []
omitted (there used to be a separate tsconfig.json
for actions) -- I can double check which Convex version this was in (edit: was 0.9.2 https://blog.convex.dev/announcing-convex-0-9-2/)
npx convex codegen --init
should update all the tsconfig
sOh whoa, I didn't even realize their used to be a
tsconfig.json
just for actions! r/outoftheloop
Ok, I'll run that and see what happens
Interesting (maybe?) to note that my tsconfig.json
includes
but no ./actions
directory. Do actions need to live in such a location? Or did they used to? I haven't used Convex's action functions before.
This project was created ~1 month ago, for reference
3 weeks maybe
Ok yeah, what you described occurred @sshader—no more types
field (also no more "./actions"
path in exclude
), and tsserver
is happy
Thanks!Yeah, actions need to leave in that directory for now.
Oh ok, good to know. Did I miss that in the docs?
Ah I see, under https://docs.convex.dev/using/actions#defining-actions. Thanks, sorry for missing it!
No worries, it is not the most elegant solution so we are working on improving it.