T
TanStack5mo ago
eastern-cyan

netlify deploy error

When deploying to Netlify, It fails building the app, with the message that env vars shouldn't be used in client code. How can I solve this?? Netlify logs: 11:45:38 PM: Secret env var "VITE_CONVEXURL"'s value detected: found value at line 1464 in .netlify/functions-internal/server/chunks//ssr.mjs 11:45:38 PM: found value at line 68 in .tanstack/start/build/client-dist/assets/main-BHcXIkoc.js 11:45:38 PM: found value at line 68 in dist/assets/main-BHcXIkoc.js 11:45:38 PM: ​ 11:45:38 PM: To prevent exposing secrets, the build will fail until these secret values are not found in build output or repo files. Refering to this code (I think):
const CONVEX_URL = (import.meta as any).env.VITE_CONVEX_URL!
if (!CONVEX_URL) {
console.error('missing envar CONVEX_URL')
}
const convexQueryClient = new ConvexQueryClient(CONVEX_URL)
const CONVEX_URL = (import.meta as any).env.VITE_CONVEX_URL!
if (!CONVEX_URL) {
console.error('missing envar CONVEX_URL')
}
const convexQueryClient = new ConvexQueryClient(CONVEX_URL)
5 Replies
fair-rose
fair-rose5mo ago
cc @Netlify (Partner)
eastern-cyan
eastern-cyanOP5mo ago
I used process.env.___, and now there's no error. Not sure why...
ambitious-aqua
ambitious-aqua5mo ago
process.env is generally for envs destined for the server import.meta.env.VITE_<name> is for client
rising-crimson
rising-crimson5mo ago
You can also check out "Manage false positives" here: https://docs.netlify.com/manage/security/secret-scanning/
eastern-cyan
eastern-cyanOP5mo ago
Thanks, that's what I found out...

Did you find this page helpful?