I am trying to use TypeScript's paths functionality so that I don't need to use relative imports any more.
Here is my tsconfig.json file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": ".",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"baseUrl": ".",
"allowJs": true,
"paths": {
"*": ["node_modules/*", "src/*"],
"@config/*": ["src/config/*"],
"@controllers/*": ["src/controllers/*"],
"@middlewares/*": ["src/middlewares/*"],
"@models/*": ["src/models/*"],
"@routes/*": ["src/routes/*"],
"@types/*": ["src/types/*"],
"@utils/*": ["src/utils/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "firebase-config.json", "webpack.config.js"]
}
Here is my package.json file:
{
"name": "express-ts-boilerplate",
"version": "0.1.0",
"description": "Express Typescript Boilerplate",
"main": "src/server.js",
"author": "Sriram R",
"scripts": {
"start": "NODE_ENV=production node dist/src/app.js",
"dev": "nodemon src/app.ts",
"build": "tsc -p .",
"test": "mocha --exit -r ts-node/register src/tests/*.spec.ts"
},
"dependencies": {
// Dependencies here
},
"devDependencies": {
// Dependencies here
},
}
So now in one of my files, I try @config/typeConfig
but I just get cannot find module
error.
Maybe it's because of nodemon
but it didn't work with ts-node
too.
How can I get this to work?