-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
π Search Terms
ESM ts.sys undefined
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about modules
β― Playground Link
https://github.com/stevebeauge/tsc-api-esm
π» Code
import * as tsc from "typescript";
const tsSystem = tsc.sys;
console.log({ tsSystem });
π Actual behavior
If I transpile this code into CJS and run node index.cjs
works as expected (tsc.sys is defined).
If I transpile this code into ESM and run node index.mjs
the code does not works as expected (tsc.sys is undefined).
π Expected behavior
tsc.sys (System
) should be available in CLI tools, whether the output is ESM or CJS.
Additional information about the issue
The issue occurs when trying to create a CLI tool that require parsing tsconfig files, including potential "extends". Typescript provides an API for that.
However, my cli tool requires to be ESM because of some imports not available as CJS.
Repro steps (using pnpm but it does not matter):
git clone https://github.com/stevebeauge/tsc-api-esm
cd tsc-api-esm
pnpm i
node index.cjs
node index.mjs
When using cjs : OK
When using ESM : KO
My investigations leds me to :
TypeScript/src/compiler/core.ts
Line 2748 in 80ab111
&& typeof module === "object"; |
It populates the tsc.sys when the function "isNodeLikeSystem" returns true. However, the test expect to have module
be defined (which is true in CJS, not in ESM).