From 3e5fa569567910701b43bb519f2b2a43a820b810 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 20 May 2020 11:59:42 +0200 Subject: [PATCH] fix(dev-infra): ensure ts-node is registered with commonjs as module (#37217) We recently added support for automatic registration of `ts-node` when the dev-infra configuration is loaded. In addition to registering ts-node, we should also ensure that the `commonjs` module is set up. By default, `ts-node` would use ES module imports that are not supported by default in NodeJS. PR Close #37217 --- dev-infra/utils/config.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dev-infra/utils/config.ts b/dev-infra/utils/config.ts index 3c73301640..67be487067 100644 --- a/dev-infra/utils/config.ts +++ b/dev-infra/utils/config.ts @@ -7,8 +7,9 @@ */ import {existsSync} from 'fs'; -import {join} from 'path'; +import {dirname, join} from 'path'; import {exec} from 'shelljs'; + import {isTsNodeAvailable} from './ts-node'; /** @@ -83,7 +84,12 @@ function readConfigFile(configPath: string): object { // version of the given configuration seems to exist, set up `ts-node` if available. if (require.extensions['.ts'] === undefined && existsSync(`${configPath}.ts`) && isTsNodeAvailable()) { - require('ts-node').register({skipProject: true, transpileOnly: true}); + // Ensure the module target is set to `commonjs`. This is necessary because the + // dev-infra tool runs in NodeJS which does not support ES modules by default. + // Additionally, set the `dir` option to the directory that contains the configuration + // file. This allows for custom compiler options (such as `--strict`). + require('ts-node').register( + {dir: dirname(configPath), transpileOnly: true, compilerOptions: {module: 'commonjs'}}); } try {