swc: Problems with decorators when using class validator
Describe the bug
I’m trying to use Nest.js with Class Validator for body validation. I’ve created an E2E test using ts-jest that passes, and I’m using the same test with @swc/jest but it’s returning a 400 as if the fields weren’t being assigned.
Input code
In this link is the repository with the tests that reproduces the error. Run yarn test:e2e for running the tests with ts-jest and test:e2e:swc for @swc/jest.
The problem is at src/app.controller.ts:17.
Another problem, is that the import * as request from 'supertest' is working with ts-jest but not with @swc/jest. The error is TypeError: request is not a function
Config
Check the .swcrc file at the repo.
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
},
"target": "es2018"
},
"module": {
"type": "commonjs"
}
}
Expected behavior
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 19 (7 by maintainers)
Commits related to this issue
- Add tests for #1362 — committed to kdy1/swc by kdy1 3 years ago
- Second issue of #1362 was wrong — committed to kdy1/swc by kdy1 3 years ago
- #1362 — committed to kdy1/swc by kdy1 3 years ago
- fix: Fix bugs (#1590) swc_ecma_transforms_proposal: - Detect decorators in typescript parameter properties. (#1456) swc: - Add tests for #1362. (#1362) — committed to swc-project/swc by kdy1 3 years ago
- Add a test for #1362 — committed to kdy1/swc by kdy1 3 years ago
- Use correct test for #1362 — committed to kdy1/swc by kdy1 3 years ago
- https://github.com/swc-project/swc/issues/1362 — committed to swc-project/helpers by kdy1 3 years ago
- Add a test for #1362 — committed to kdy1/swc by kdy1 3 years ago
- Use correct test for #1362 — committed to kdy1/swc by kdy1 3 years ago
- fix(es): Fix bugs (#2055) swc_ecma_parser: - Fix panic from span assertion. (#2040) swc_ecma_transforms_compat: - Fix handling of `await for`. (#1918) swc_ecma_transforms_base: - Allow us... — committed to swc-project/swc by kdy1 3 years ago
Hey, I can confirm that
class-transformeris not working well either.I have following setup
But, unfortunately when I do
plainToClasson such an entityPassing down
{ query: '', pagination: { skip:0, limit: 20 } }it fails to convert returning empty object ofGetUsersOptionsInputinput. E.g. logging this to consoleconsole.log(input)->GetUsersOptionsInput {}If decorators will start to work as expected SWC will be a way to go. Ah, also unsure what’s wrong but for IntelliJ debugging with
node -r @swc/register ./src/index.tshalf broke and doesn’t stop in certain files. Mind that in most of the files there are lots of lots decorators, so that’s maybe why.Thanks, but seems like lots of investigation is still required to reduce the test case and spot the error.
Hello @kdy1, thanks a lot for your comment and great work! The noModuleInterop option worked for me. The thing is, that the main issue, still persist. I think that decorators are still not working.
These are the outputs from the example repository I gave at the top:
Unitary tests:
And also, the e2e tests are not working with swc:
I think there might be a problem with de decorators because when I remove the decorators from the
CreateUserDtoit works.I’ve updated all the dependencies of the example repository so you can try it out.
Thanks a lot again!
I tried fixing this, but babel also emits error for
and it’s logically correct.
You need to set
jsc.module.noInteropto true lkeIf so, swc works.