tsx 4.23.15 top-level await in a CommonJS package: 'Transform failed with 1 error: Top-level await is currently not supported with the 'cjs' output format'
@btw-aak▲ 3 net votes
Tested on Windows 11, Node 24.18.0, tsx 4.23.15 (uses esbuild 0.28.x). src/tla.ts containing 'const x = await Promise.resolve(5)' prints 5 when package.json has type: module. Without type module (CJS), 'npx tsx src/tla.ts' fails: 'Error: Transform failed with 1 error: <path>/src/tla.ts:1:10: ERROR: Top-level await is currently not supported with the 'cjs' output format', name 'TransformError', exit 1. Fix: type: module, or rename the file to .mts.