I am relatively new to TypeScript and the compilation process, so please bear with me if I am missing something obvious.
I have an express API written in TypeScript using tsoa decorators to generate docs from the code.
In my app the source code is located in /src, and then transpiled to /dist at build time. tsoa automatically generates a routes file that is compiled to /dist/routes.js (tedious system btw).
The issue I am facing is that in the built routes.js
file, all the controllers are referenced using the path ../src
.
This causes the application to fail when running from the compiled version (which is what I'll do once in production) unless I manually change the paths to reference the compiled files instead.
For example, to make the following controller work, I have to change the import statement in routes.js from:
const LocationController_1 = require("./../src/controllers/LocationController");
to:
const LocationController_1 = require("./controllers/LocationController");
Since the routes file is generated automatically by tsoa, it should not be manually modified.
However, I have followed the instructions in the documentation for tsoa and TypeScript thoroughly and have not been able to resolve the issue. I have also researched this issue and came across, but since tsoa handles the whole process of controller discovery, I cannot force it to use an alias for the path, tsconfig-paths can be another solution but I wasn't able to configure it properly.
Is there something that I am missing?
Any guidance or suggestions would be greatly appreciated.
Here is my tsconfig.json
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"lib": [
"DOM",
"ES6",
"ESNext.AsyncIterable"
],
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": "./",
"moduleResolution": "node",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false,
"resolveJsonModule": true
}
}
Here's what I've tried to with aliasing paths
"paths": {
"@controllers/": [
"./src/controllers/*"
]
}
In tsoa.json I've tried to use the alias to find the controllers
"controllerPathGlobs": [
"@controllers/*"
],
This does not find any controller.
I've also tried to use this in tsconfig
"paths": {
"../src/controllers": [
"./controllers"
]
}
I'm pretty sure something obvious is missing here...!
Thank you for your help, and I apologize for any confusion or mistakes in my explanation.