I spent a while trying to get my project to bundle using tsup and the issue was that I was importing TsoaResponse directly rather than as a type in my controller - like so:
import { Get, Route, Tags, Post, Body, Path, Response, SuccessResponse, Controller, Res, TsoaResponse } from "tsoa"
// should have been seperately
// import type { TsoaResponse } from "tsoa"
This was causing tsup to bundle the import and seeing as TSOA uses CJS and my packages uses ESM it wasnt able to find it and I couldnt run my built package - I wasted far too long trying to figure this out.
Normally I would catch these problems with my eslint rule: "@typescript-eslint/consistent-type-imports" : [ "error", { "prefer": "type-imports", "fixStyle": "separate-type-imports" } ],
However that rule doesnt work in file that uses decorators (like a controller) if experimentalDecorators and emitDecoratorMetadata are both set to true in tsconfig.json - which are required by tsoa.
This is mentioned in the caveat here: https://typescript-eslint.io/rules/consistent-type-imports
Instead the verbatimModuleSyntax: true option at least shows me an error in the IDE which would have saved a lot of debugging time, and also should really be the standard, as if you're exporting as a type it should really only be imported as a type.
It would be nice to atleast have an option to properly seperate the type imports in the built routes, or to convert tsoa ESM.
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
Routes should be compiled to:
Current Behavior
Routes imports are compiled to
Possible Solution
Suggestions in similar issues: https://github.com/lukeautry/tsoa/issues/1418 https://github.com/lukeautry/tsoa/issues/1628
Detailed Description
I spent a while trying to get my project to bundle using
tsup
and the issue was that I was importingTsoaResponse
directly rather than as a type in my controller - like so:This was causing tsup to bundle the import and seeing as TSOA uses CJS and my packages uses ESM it wasnt able to find it and I couldnt run my built package - I wasted far too long trying to figure this out.
Normally I would catch these problems with my eslint rule:
"@typescript-eslint/consistent-type-imports" : [ "error", { "prefer": "type-imports", "fixStyle": "separate-type-imports" } ],
However that rule doesnt work in file that uses decorators (like a controller) if
experimentalDecorators
andemitDecoratorMetadata
are both set totrue
intsconfig.json
- which are required by tsoa. This is mentioned in the caveat here: https://typescript-eslint.io/rules/consistent-type-importsInstead the
verbatimModuleSyntax: true
option at least shows me an error in the IDE which would have saved a lot of debugging time, and also should really be the standard, as if you're exporting as a type it should really only be imported as a type.It would be nice to atleast have an option to properly seperate the type imports in the built routes, or to convert tsoa ESM.