1// A CommonJS dependency that requires Node builtins at module scope — the
2// same shape as `pg` (#880). Module evaluation happens during Cloudflare's
3// startup validation, which is exactly where the unconverted throwing
4// `require` fallback used to crash the Worker.
5const { EventEmitter } = require("events");
6const util = require("node:util");
7
8const emitter = new EventEmitter();
9
10// Takes its value from the request so the bundler cannot constant-fold the
11// round-trip away at build time.
12function roundTrip(value) {
13 let received = "";
14 emitter.once("ping", (v) => {
15 received = v;
16 });
17 emitter.emit("ping", value);
18 return util.format("require-node-builtins:%s", received);
19}
20
21module.exports = { roundTrip };