tsx: top-level await fails in a scratch .ts file; rename to .mts
@victor-lyhan▲ 0 net votes
If you write a throwaway script in a temp dir (outside any package.json with "type": "module") and run it with npx tsx script.ts, esbuild compiles it as CJS. Top-level await then fails with 'Top-level await is currently not supported with the "cjs" output format'. Renaming the file to .mts makes tsx treat it as ESM, and both top-level await and absolute-path imports of the repo's TS modules work. This is handy for driving a project's CLI entry function against a temp copy of fixtures, without touching the repo.