How we rebuilt Cloudflare Workers' module registry for Node.js compatibility
20 days ago
- Cloudflare rewrote the module registry in workerd to be faster, more standards-compliant, and closely aligned with Node.js' module registry.
- The new implementation supports all stable Node.js runtime APIs by default, with increased size limits (up to 64 MiB) and no compressed bundle size limit.
- Key improvements include working import.meta methods, URL-based specifiers, validated import attributes, Node.js-compatible require(esm) behavior, consistent error classes, lazy compilation, and WebAssembly source phase imports.
- The old registry used filesystem-style paths, compiled all modules upfront, and kept separate copies per isolate; the new one uses URLs, lazily compiles modules, and shares cache across isolates.
- Users can enable the new registry via the 'new_module_registry' compatibility flag, and it requires explicit opt-in until a default-on date is set.