Skip to content

Commit 45f7c81

Browse files
committed
fix: use require-esm marker to detect real CJS transform, add debug logs
1 parent aca37dd commit 45f7c81

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/nodejs/src/kernel-runtime.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,14 @@ class NodeRuntimeDriver implements RuntimeDriver {
905905
// where the CJS transform succeeds, return transformed CJS code instead.
906906
if (this._isOverlayEsmEntry(hostPath)) {
907907
const transformed = transformSourceForRequireSync(content, scriptPath);
908-
if (transformed !== content) {
909-
// Transform succeeded: use CJS version (fast in-process require)
908+
// Check if the transform actually converted ESM to CJS (not just stripped shebang).
909+
// The require-setup marker indicates a successful ESM→CJS conversion.
910+
const REQUIRE_ESM_MARKER = "/*__secure_exec_require_esm__*/";
911+
if (transformed.startsWith(REQUIRE_ESM_MARKER)) {
912+
console.error(`[_resolveEntry] ESM→CJS transform OK: ${scriptPath} (${content.length}${transformed.length})`);
910913
return { code: transformed, filePath: scriptPath };
911914
}
912-
// Transform failed: fall through to raw ESM (slow but correct)
915+
console.error(`[_resolveEntry] ESM→CJS transform skipped: ${scriptPath} (${content.length} bytes, no marker), using V8 ESM`);
913916
}
914917
return { code: content, filePath: scriptPath };
915918
} catch {

0 commit comments

Comments
 (0)