Error fixes / Bolt
Bolt
Bolt: process is not defined
Browser code read process.env, which exists in Node and not in the page.
The error
Uncaught ReferenceError: process is not defined
What it means
Vite, which Bolt uses for many frontends, does not provide process.env in the browser. The ReferenceError is the browser telling you process was never declared. Vite exposes variables on import.meta.env, and only names that start with VITE_ are included in the client. A server key must not be renamed to VITE_ just to silence this error.
Fix
- Find process.env in files that run in the browser. Replace public values with import.meta.env.VITE_...
- Move any read of a secret to a server route. Do not add the VITE_ prefix to a secret.
- Restart the dev server after changing env files. Vite reads them at startup.
- If the project is Next.js rather than Vite, use the Next env rules instead. NEXT_PUBLIC_ is the public prefix there, and process.env works on the server.
- Rebuild and confirm the browser console is clear, and that the secret string is not in the JavaScript bundle.
Prompt
Fix prompt
The browser throws ReferenceError: process is not defined. This is a Vite frontend. Replace client reads of process.env with import.meta.env.VITE_ names for public values only. Move secret reads to server code. Do not prefix a secret with VITE_. Restart notes belong in a comment for me: I must restart the dev server. List the public variable names. Do not print values.
Questions
Why did the agent use process.env?
That is the Node habit. The file ended up in the browser bundle, where process does not exist unless you define it. Match the tool: Vite uses import.meta.env.
Can I define process.env in the Vite config to make it work?
You can polyfill it, and you will also risk inlining secrets. Prefer the Vite env names, and keep secrets on the server.
The variable is set and still undefined. Why?
It may be missing the VITE_ prefix, the dev server was not restarted, or you set it on the host but did not rebuild the client.