# Node builtin errors in Workers builds

The errors look like `process is not defined`, `Buffer is not defined`, or `Dynamic require of "buffer" is not supported`. They share one root cause: code (yours or a dependency's) touches a Node.js builtin that is not available in the workerd runtime.

## Diagnose in order

1. **Check the compatibility_date first.** For dates `2026-08-04` or later, `nodejs_compat` and `nodejs_compat_v2` are on by default and real Node builtins are available. For `2024-09-23` to `2026-08-03`, add `"nodejs_compat"` to `compatibility_flags`. For older dates, bump the date; do not patch the package first.

2. **Built-in vs shim.** With the flag on, some Node APIs are full runtime implementations and some are Wrangler-added polyfill shims. Shims let the import succeed but throw when called. If the error moved from build time to runtime after enabling the flag, you are calling a shimmed API: check the supported Node.js APIs list and replace the call.

3. **Bundler shims.** `process is not defined` in a Vite build usually means a dependency references `process.env` and the bundler did not define it. The Vite plugin / Wrangler define some of these, but a library reaching for `process` directly needs the compat flag plus, sometimes, an explicit `define` in build config.

## The traps

- Adding the flag to fix a build error, then shipping without testing the runtime path: the shim throws in production instead.
- `require()` of Node builtins in ESM Workers: use `node:` prefixed imports so the bundler routes them to the runtime implementations.

## Checklist

- Reproduce with the compat date current before touching dependencies.
- If a dependency fundamentally needs unsupported Node APIs (child_process, native addons), it cannot run on Workers; find an alternative or move that code to a container/VM.