T
TanStack3mo ago
probable-pink

Server side environment variables in production?

I'm trying to use node-server to serve my application. In DEV, all my environment variables (like DATABASE_URL) are working fine. When I go to serve with node ./.output/server/index.mjs, none of my server environment variables are there. Is there a common solution for this? I'm on 1.121.21
> node ./.output/server/index.mjs

Listening on http://[::]:3000
❌ Invalid environment variables: [
{
code: 'invalid_type',
expected: 'string',
received: 'undefined',
path: [ 'DATABASE_URL' ],
message: 'Required'
},
> node ./.output/server/index.mjs

Listening on http://[::]:3000
❌ Invalid environment variables: [
{
code: 'invalid_type',
expected: 'string',
received: 'undefined',
path: [ 'DATABASE_URL' ],
message: 'Required'
},
1 Reply
probable-pink
probable-pinkOP3mo ago
Seems like my Node polyfill was causing some issues.
export default defineConfig({
server: {
port: 3000,
},
plugins: [
tsConfigPaths(),
tanstackStart({
target: "node-server",
}),
tailwindcss(),
// nodePolyfills({
// include: ["buffer"],
// globals: {
// Buffer: true,
// global: true,
// },
// }),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
});
export default defineConfig({
server: {
port: 3000,
},
plugins: [
tsConfigPaths(),
tanstackStart({
target: "node-server",
}),
tailwindcss(),
// nodePolyfills({
// include: ["buffer"],
// globals: {
// Buffer: true,
// global: true,
// },
// }),
],
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
});
Running vite build and then node --env-file=.env .output/server/index.mjs works!

Did you find this page helpful?