From a4ab0148a321a302cec055896ab312840e9bfbc6 Mon Sep 17 00:00:00 2001 From: Satoshi Qazi Muhammed Date: Wed, 7 Oct 2026 08:09:35 +0400 Subject: [PATCH] Keep import() of an ES module in the CommonJS output The CJS build transpiled with module CommonJS and NodeNext resolution. On TypeScript 5.5 that kept import() of an ES module; from 5.6 it becomes require(), which an ES module cannot answer on Node before 22. CJS is now emitted with module NodeNext, under which TypeScript must keep import() for an ES module. Across this repository's output the only change is that line, plus a strict-mode header on one file with no imports. Co-Authored-By: Claude Opus 5.5 (1M context) --- packages/dev/scripts/pezkuwi-dev-build-ts.mjs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/dev/scripts/pezkuwi-dev-build-ts.mjs b/packages/dev/scripts/pezkuwi-dev-build-ts.mjs index 02f2f17..bbd9c41 100755 --- a/packages/dev/scripts/pezkuwi-dev-build-ts.mjs +++ b/packages/dev/scripts/pezkuwi-dev-build-ts.mjs @@ -73,7 +73,12 @@ async function compileJs (compileType, type) { const source = fs.readFileSync(filename, 'utf-8'); - // compile with the options aligning with our tsconfig + // compile with the options aligning with our tsconfig. CJS is emitted + // under Node's own rules (NodeNext; a lone file is taken as CommonJS): + // CommonJS with NodeNext resolution kept `import()` of an ES module on + // TypeScript 5.5 and turned it into require() from 5.6 on, which an ES + // module cannot answer on Node before 22 (rootEsm.spec "contains + // import(...) in cjs"). const { outputText } = ts.transpileModule(source, { compilerOptions: { esModuleInterop: true, @@ -82,11 +87,12 @@ async function compileJs (compileType, type) { ? ts.JsxEmit.ReactJSX : undefined, module: type === 'cjs' - ? ts.ModuleKind.CommonJS + ? ts.ModuleKind.NodeNext : ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.NodeNext, target: TARGET_TSES - } + }, + fileName: filename }); mkdirpSync(path.dirname(outFile)); @@ -448,6 +454,7 @@ function relativePath (value) { if (!value || typeof value !== 'string') { return ''; } + return value.startsWith('.') ? value : `./${value}`; }