diff --git a/src/bun.js/modules/NodeModuleModule.cpp b/src/bun.js/modules/NodeModuleModule.cpp index 67c8de6780..6655ea9fbc 100644 --- a/src/bun.js/modules/NodeModuleModule.cpp +++ b/src/bun.js/modules/NodeModuleModule.cpp @@ -698,6 +698,8 @@ static JSValue getModulePrototypeObject(VM& vm, JSObject* moduleObject) setterRequireFunction), 0); + prototype->putDirect(vm, Identifier::fromString(vm, "_compile"_s), globalObject->modulePrototypeUnderscoreCompileFunction()); + return prototype; } diff --git a/test/cli/run/run-eval.test.ts b/test/cli/run/run-eval.test.ts index 84b30f80e7..cb94d1fb56 100644 --- a/test/cli/run/run-eval.test.ts +++ b/test/cli/run/run-eval.test.ts @@ -133,6 +133,14 @@ describe("--print for cjs/esm", () => { expect(stdout.toString("utf8")).toEqual("object object function string string\n123\n"); expect(exitCode).toBe(0); }); + test("module._compile is require('module').prototype._compile", async () => { + const { stdout, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "-p", "module._compile === require('module').prototype._compile"], + env: bunEnv, + }); + expect(stdout.toString()).toBe("true\n"); + expect(exitCode).toBe(0); + }); }); function group(run: (code: string) => SyncSubprocess<"pipe", "inherit">) {