For a Node 20 application with Typescript, I’m switching to ESM.
Since, I’m importing ts files, I’ve made a change in my Typescript config file:
{
"compilerOptions": {
"target": "ES2020",
"module": "esnext",
"moduleResolution": "node",
"typeRoots": ["./src/types"],
"allowImportingTsExtensions": true, // Changed this one.
"resolveJsonModule": true,
"outDir": "./dist/",
"noEmit": true, // Changed this one too.
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": false,
"skipLibCheck": true
}
}
My build script is simple: tsc
.
Locally, both start and build scripts work. But my docker pipeline fails. The docker pipeline includes COPY --from=builder ./app/dist .
but because of noEmit
the dist
folder is never created. But if I set noEmit and allowImportingTsExtensions to false, it fails with the error: “An import path can only end with a ‘.ts’ extension when ‘allowImportingTsExtensions’ is enabled.”.
How am I supposed to make ESM work with Typescript?