Overriding Compiler Options in tsconfig.json

I'm trying to use rollup to package my little library. It wants me to set the output to "esnext" really badly. (The warning is: Unless you know what you're doing, please change "module" to "esnext" in the target tsconfig.json file or plugin options. and I have to say... I don't have a compelling reason to object)

Except for the fact that ts-node, which I've been using to run my scripts, really doesn't like that. It wants me to set the type to module. I tried a few things like renaming the file to .mjs and '.mts, but nothing was working.

dan@Dans-MacBook-Pro canisoon-lib % yarn ts-node src/start.ts
yarn run v1.22.5
$ /Users/dan/code/js/canisoon/canisoon-lib/node_modules/.bin/ts-node src/start.ts
(node:36461) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/dan/code/js/canisoon/canisoon-lib/src/start.ts:1
import { asLine, detailView } from './feature';
^^^^^^

I was feeling pretty stuck.

But I figured I couldn't be the first person who wanted to use rollup and ts-node. So I turned to the docs and happened across this helpful comment:

f you must keep "module": "ESNext" for tsc, webpack, or another build tool, you can set an override for ts-node.

It's turns out possible to embed ts-node specific options in the tsconfig file. So now the bottom of my tsconfig file has:

  //  .. a lot of automatically generated content.. //
    // "emitDecoratorMetadata": true,               /* Enables experimental support for emitting type metadata for decorators. */

    /* Advanced Options */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true        /* Disallow inconsistently-cased references to the same file. */
  },
  "ts-node": {
    "compilerOptions": {
      "module": "CommonJS"
    }
  }
}

And it works!!

postscript

I thought that this might be a general that Typescript does - allow . But I didn't see anything in their docs about it. I did notice tsNodeDefinition in the schema, so I guess they specifically defined enabled this feature for ts-node.

I wondered what other tools might be blessed with a mention in the tsconfig schema, but it was the only one. Every other section at the same area of the schema is something much more generic and fundamental, like buildOptionsDefinition and filesDefinition.

So ts-node must be a much more widely used package than I first realized.