fix(node): emit warning for unimplemented module.register()

module.register() is used by OpenTelemetry and other tooling to register
ESM loader hooks. Since this feature is not yet implemented in Bun, this
change emits a process warning to inform users that their loaders will
not be invoked, along with a pointer to Bun's plugin API as an alternative.

Fixes #3775

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-15 00:58:38 +00:00
parent 22bebfc467
commit 58a3c2c863
2 changed files with 75 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
#include "root.h"
#include "headers-handwritten.h"
#include "NodeModuleModule.h"
#include "BunProcess.h"
#include <JavaScriptCore/JSCInlines.h>
#include <JavaScriptCore/VM.h>
@@ -870,6 +871,13 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionSyncBuiltinESMExports,
JSC_DEFINE_HOST_FUNCTION(jsFunctionRegister, (JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
auto& vm = globalObject->vm();
Bun::Process::emitWarning(
globalObject,
jsString(vm, String("module.register() is not implemented in Bun. Loaders registered with module.register() will not be invoked. To intercept and transform modules, consider using Bun's plugin API: https://bun.sh/docs/bundler/plugins"_s)),
jsString(vm, String("Warning"_s)),
jsString(vm, String("BUN_UNSUPPORTED_REGISTER"_s)),
jsUndefined());
return JSC::JSValue::encode(JSC::jsUndefined());
}