How to Make ENV Accessible in a TanStack Start Server Build?
I'm using the Clerk example: Clerk Basic Example
Environment Variables
I have the following in my
.env
:
App Config
My app.config.ts
uses the node-server
preset since I plan to host on AWS Lightsail:
Debugging Logs
After running the build, in my __root.tsx
I added:
- Result: Only VITE_CLERK_*
variables are visible in both logs during the build.
Server Function
Here’s the function that calls Clerk auth:
- Error:
My Question
How do I make the server see CLERK_SECRET_KEY
in the built version?7 Replies
like-goldOP•8mo ago
I updated the command to be this:
I know this is the not best way but it includes the env for now
wise-white•8mo ago
Did you update youir package.json > build: "node --env-file=.env .output/server/index.mjs && vinxi build"?
how do you build it without vinxi?
like-goldOP•8mo ago
these are the commands in the package.json
I am currently using vinxi build. The issue is when I run the built version
node .output/server/index.mjs
, I can't see the env.
I added the --env-file=.env
as a quick fix, but its not the best way to do itwise-white•8mo ago
aha. that will not remove the Error: @clerk/tanstack-start: Clerk: no secret key provided, but already a good solution right now.
I am not sure if that will require you to get the prod instance of your clerk connection.
like-goldOP•8mo ago
It works on the VPS when I ran it on a prod instance with pm2
wise-white•8mo ago
That's really good.
dependent-tan•7mo ago
Hello, I ran into same issue, and as per vinxi server gh discussions (https://github.com/nksaraf/vinxi/issues/277), it's not possible to load env vars file using
vinxi start
.
The work around with node --env-file=.env .output/server/index.mjs
did the job locally.