diff --git a/.changeset/three-snakes-deny.md b/.changeset/three-snakes-deny.md new file mode 100644 index 0000000000..8de233f870 --- /dev/null +++ b/.changeset/three-snakes-deny.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +The Node.js transform in `@backstage/cli/config/nodeTransformHooks.mjs` now supports the built-in type stripping in Node.js, which is enabled by default from v22.18.0. diff --git a/packages/cli/config/nodeTransformHooks.mjs b/packages/cli/config/nodeTransformHooks.mjs index 0e7b14f929..7bf0473bb8 100644 --- a/packages/cli/config/nodeTransformHooks.mjs +++ b/packages/cli/config/nodeTransformHooks.mjs @@ -255,6 +255,18 @@ export async function load(url, context, nextLoad) { return nextLoad(url, { ...context, format }); } + // If the Node.js version we're running supports TypeScript, i.e. type + // stripping, we hand over to the default loader. This is done for all cases + // except if we're loading a .ts file that's been resolved to CommonJS format. + // This is because these files aren't actually CommonJS in the Backstage build + // system, and need to be transformed to CommonJS. + if ( + format === 'module-typescript' || + (format === 'module-commonjs' && ext !== '.ts') + ) { + return nextLoad(url, { ...context, format }); + } + const transformed = await transformFile(fileURLToPath(url), { sourceMaps: 'inline', module: {