tsoa
tsoa copied to clipboard
Custom middleware does not work with esbuild because emitDecoratorMetadata is not supported
https://github.com/lukeautry/tsoa/issues/961
According to this ticket, tsoa
doesn't rely on the emitDecoratorMetadata
TS option. That seemed correct at the time of writing, but sadly appears to no longer be true: https://github.com/lukeautry/tsoa/blob/acdfeb4d398fa7416dd10e251029d9e109c216d3/packages/runtime/src/decorators/middlewares.ts#L41
Because esbuild
doesn't support emitDecoratorMetadata
, it appears that custom middleware via the @Middlewares
annotation cannot be used with esbuild.
Is there any advice for a workaround?
Sorting
-
I'm submitting a ...
- [ ] bug report
- [ ] feature request
- [x] support request
-
I confirm that I
- [x] used the search to make sure that a similar issue hasn't already been submit
Expected Behavior
Current Behavior
Possible Solution
Steps to Reproduce
Context (Environment)
Version of the library: Version of NodeJS:
- Confirm you were using yarn not npm: [ ]
Detailed Description
Breaking change?
Hello there jsamilow 👋
Thank you for opening your very first issue in this project.
We will try to get back to you as soon as we can.👀
You need decorators/reflection, but I am not sure why the snippet you referenced would need the emitted metadata
Maybe I am misreading, but you are using Reflect.getMetadata
: https://github.com/lukeautry/tsoa/blob/acdfeb4d398fa7416dd10e251029d9e109c216d3/packages/runtime/src/decorators/middlewares.ts#L52-L53
According to the documentation for this library, you need emitted metadata. This library doesn't appear to be used anywhere else in the code.
Also see https://stackoverflow.com/questions/68570519/why-cant-reflect-metadata-be-used-in-vite
Any update? Note that the middleware works fine when I run the application with ts-node
, so it's plainly the use of esbuild
that's tripping things up. If you're open to a pull request to remove the dependency on reflect-metadata
I would look into how much work is involved.
I don't know what the status is for esbuild on supporting decorators. My understanding is that emitDecoratorMetadata only adds additional information about the shape of the target which we don't rely on afaik.
Current workaround: Use TS-Node, TSC or SWC
E: But we can test this: Does TSC with emitDecoratorMetadata= false work? If the answer is no I'd be happy to take a closer look
We fixed it. It turns out the issue is import {Middlewares} from 'tsoa'
. It works if we do import {Middlewares} from '@tsoa/runtime'
. This is surprising but it works. I guess I was barking up the totally wrong tree. Sorry about that and thanks for looking!
@jsamilow thanks for the suggestion! Build fails if I'm importing from tsoa
but it works just fine with @tsoa/runtime