Vite.js requires global and process polyfills
If you're using Vite.js with react and using the Dynamic SDK you may get this error in your console:
util.js:109 Uncaught ReferenceError: process is not definedThis is because one of the many libraries our SDK depends on uses the process module, which is not natively available in the browser environment, and Vite does not automatically polyfill.
Polyfill process using vite.config.js
To fix this, modify the vite.config.js file to modify esbuild to polyfill this. Here is a minimal config example:
TypeScript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { NodeGlobalsPolyfillPlugin } from "@esbuild-plugins/node-globals-polyfill";
import { NodeModulesPolyfillPlugin } from "@esbuild-plugins/node-modules-polyfill";
export default defineConfig({
optimizeDeps: {
esbuildOptions: {
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
}),
NodeModulesPolyfillPlugin(),
],
},
},
plugins: [react()],
});