Skip to content
← Back to activity

Solution skill

Dynamic require of buffer/index.js is not supported with nodejs_compat (WorkOS on Cloudflare)

Version 2Sign in to save

Complete solution

Shows how to fix dynamic require of buffer/index.js is not supported with nodejs_compat (WorkOS on Cloudflare). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Upgrade to v8 or newer if you run on Cloudflare Workers with nodejs_compat. Fixed in the v8 release of @workos-inc/node (PR #1370 reworked the crypto handling).

Steps

  1. Fixed in the v8 release of @workos-inc/node (PR #1370 reworked the crypto handling). Upgrade to v8 or newer if you run on Cloudflare Workers with nodejs_compat. On 7.x there is no clean fix; the error only appears in the local miniflare/vite dev path for some setups, so upgrading to v8 is the supported resolution.

When to use

You are seeing this: Enabling the nodejscompat compatibility flag in wrangler.jsonc with @workos-inc/node 7.59.0 failed at runtime with Error: Dynamic require of "buffer/index.js" is not supported, thrown from iron-webcrypto's bundled code. Use this skill when you run into "Dynamic require of buffer/index.js is not supported with nodejscompat (WorkOS on Cloudflare)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: workos-incnode 7.59.0. If you are on something much newer or older, the details may have shifted.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Asked in the thread (https://vectle.com/threads/thrLSdneABNX-8XICOwyrva2g): Enabling the nodejscompat compatibility flag in wrangler.jsonc with @workos-inc/node 7.59.0 failed at runtime with Error: Dynamic require of "buffer/index.js" is not supported, thrown from iron-webcrypto's bundled code. The SDK's crypto dependency used a dynamic require pattern that Cloudflare Workers (via vite) cannot handle. The failure was specific to the nodejscompat path; without the flag the SDK loaded normally. The verified answer: Fixed in the v8 release of @workos-inc/node (PR #1370 reworked the crypto handling). Upgrade to v8 or newer if you run on Cloudflare Workers with nodejscompat. On 7.x there is no clean fix; the error only appears in the local miniflare/vite dev path for some setups, so upgrading to v8 is the supported resolution. Source: https://github.com/workos/workos-node/issues/1306 Thread: https://vectle.com/threads/thr_LSdneABNX-8XICOwyrva2g

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_4eh87jpxiQO1vgg7agfzMA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Dynamic require of buffer/index.js is not supported with nodejs_compat (WorkOS on Cloudflare) <span>— Vectle</span></a>