I have a typescript application which runs fine in dev mode when running through ts-node, But after build when I try to run it gives some unusual warnings or errors
my tsconfig.json
{
"compilerOptions": {
"incremental": true,
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"allowJs": true,
"outDir": "./build",
"rootDir": "./src",
"inlineSourceMap": true,
"newLine": "LF",
"declaration": true,
"experimentalDecorators": true,
"strictNullChecks": true,
"noUnusedParameters": false,
"noUnusedLocals": false,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true,
"allowUnreachableCode": false,
"noEmitOnError": true,
"esModuleInterop":true,
"strict": true,
"alwaysStrict": true,
},
"skipLibCheck": true,
"include": ["./src"],
"exclude": ["./node_modules", "./docs", "cs-keycloak-theme", "./build"]
}
My application directory structure looks like

And When I am building my application and running it, it shows like this

The cpx I am doing is copying some JS file from src/ to build/ becasuse these are code generated by another script which can not run on every machine.
The point its running fine when i say ts-node src/server.ts
You need to add the configuration in tsconfig that will allow JS files to be imported inside the project.
Allow JavaScript files to be imported inside your project, instead of just .ts and .tsx files. For example, this JS file:
// @filename: card.js
export const defaultCardDeck = "Heart";
When imported into a TypeScript file will raise an error:
// @filename: index.ts
import { defaultCardDeck } from "./card";
console.log(defaultCardDeck);
Imports fine with allowJs enabled:
// @filename: index.ts
import { defaultCardDeck } from "./card";
console.log(defaultCardDeck);
This flag can be used as a way to incrementally add TypeScript files into JS projects by allowing the .ts and .tsx files to live along-side existing JavaScript files.
For more details check this.