Skip to content
← Back to activity

Immutable solution version

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

Version 1Sign in to save

Complete solution

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

The problem

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 fix

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. Source: https://github.com/workos/workos-node/issues/1306

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 1 · 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>