I have a personal project using node.js, express.js and typescript.
When I run command to build project, it does all right.
But when I try to run it, it crashes, because all imports are "wrong", have a look:
The file dist/index.js has this import:
import app from './core/app';
...
BUT, if I make this change to the import, it runs ok:
import app from './core/app.js';
...
I didn't want to create a script file to do this, how can I solve it?
I'm currently using node version 16.0.
Here is my folder structure
Here is my index.ts
import app from 'src/core/app';
/**
* Initializing server
*/
app.listen(app.get('port'), () => console.log('Application running -> true'));
Here is my tsconfig.json
{
"compilerOptions": {
"lib": ["ES2021"],
"target": "ES2021",
"module": "ES2020",
"moduleResolution": "node",
"strict": true,
"baseUrl": ".",
"sourceMap": true,
"outDir": "dist",
"rootDir": "src",
"skipLibCheck": true,
"noImplicitAny": true,
"esModuleInterop": true,
"isolatedModules": true,
"removeComments": true,
"resolveJsonModule": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"useUnknownInCatchVariables": true,
"allowSyntheticDefaultImports": true,
"strictPropertyInitialization": false,
"forceConsistentCasingInFileNames": true,
"typeRoots": ["node_modules/@types", "src/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}