ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

Error when tsconfig.compilerOptions.module is unsupported by Node

Open alcuadrado opened this issue 5 years ago • 2 comments

Desired Behavior

Throw an error if tsconfig.compilerOptions.module is other than "commonjs".

Is this request related to a problem?

I have a command-line application that loads ts-node if it's installed. Users can use typescript for almost everything in that case.

The problem is that some users may accidentally set the tsconfig.compilerOptions.module to incompatible values. If this happens, the errors they get are pretty hard to understand.

Alternatives you've considered

We could validate this ourselves, but that would mean reimplementing how ts-node chooses which tsconfig.json to use.

Additional context

This request should be updated if ts-node were to support the new native ESM mode of node.

alcuadrado avatar Jun 24 '20 17:06 alcuadrado

Some relevant info:

ts-node already supports native ESM. See #1007 for discussion.

We default to CommonJS if the user does not specify the module option. https://github.com/TypeStrong/ts-node/blob/master/src/index.ts#L912-L915 But we respect the user's choice if they configure it.

cspotcode avatar Jul 09 '20 16:07 cspotcode

Should this be a warning? While we know that node will probably throw when running whatever unsupported module type, we can't be 100% future proof with that. IMHO, it's a better idea to warn the user of the upcoming error than completely cut them off.

nicolas377 avatar Jul 08 '22 15:07 nicolas377