Short answer
In a Vite app, read env variables from import.meta.env, and name the ones the browser needs with the VITE_ prefix. In Next.js, browser code can only read variables named NEXT_PUBLIC_, which are inlined at build time. With webpack 5, replace the values you use with DefinePlugin. If the error comes from a library inside node_modules, it was written for Node.js: look for its browser build, or define the one value it reads.
Why process is missing, and the fix
01
process.env in a Vite app
“Variables prefixed with VITE_ will be exposed in client-side source code after Vite bundling.” Vite, Env variables and modes
Vite exposes env variables on import.meta.env, not process.env, and only those prefixed with VITE_ reach browser code. Anything else is kept out of the browser bundle, which also keeps secrets out of it.
# .env VITE_API_URL=https://api.example.com // src/api.js const baseURL = import.meta.env.VITE_API_URL;02
webpack 5 without the old Node.js shims
“Webpack 5 no longer polyfills Node.js core modules automatically” webpack, Resolve: resolve.fallback
webpack 4 quietly added a fake process object. webpack 5 does not, so code that reads process.env breaks after an upgrade. Replace the exact values at build time with DefinePlugin.
const webpack = require('webpack'); module.exports = { plugins: [ new webpack.DefinePlugin({ 'process.env.API_URL': JSON.stringify(process.env.API_URL), }), ], };03
Next.js variables without NEXT_PUBLIC_
In Next.js, process.env.SECRET works in server code but is undefined in client components, and dynamic access such as process.env[name] is never inlined. Prefix browser variables with NEXT_PUBLIC_ and read each one by its full name.
const url = process.env.NEXT_PUBLIC_SUPABASE_URL; // inlined at build time04
A library written for Node.js
When the stack trace points into node_modules, a package expects Node.js globals. Check for a browser or ESM build in its docs, or define the value it reads in your bundler config. Avoid adding a full process polyfill just to silence it.
Checked against the vendor’s docs on : Vite: Env variables and modes; webpack: Resolve (resolve.fallback).
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Vercel environment variables undefined · “require is not defined” · Firebase “invalid API key” in production