More NPM packages on Cloudflare Workers: Combining polyfills and native code to support Node.js APIs
Sep 9, 2024James M Snell, Igor Minar, James Culveyhouse, Mike Nomitch

Summary
This post introduces a hybrid model for Node.js API compatibility in Cloudflare Workers. It combines native C++ implementations of core Node.js APIs (like Buffer, async_hooks, crypto) within the workerd runtime with build-time JavaScript polyfills (using unenv) for other APIs. This approach allows for broader NPM package compatibility without requiring the `node:` prefix and results in smaller Worker sizes by only polyfilling used APIs. The new `nodejs_compat_v2` flag enables this hybrid model.