samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.84k stars 95 forks source link

TypeError: Cannot read properties of undefined (reading '0') #1059

Open ChristiaanWillemsen opened 3 weeks ago

ChristiaanWillemsen commented 3 weeks ago

Summary

Write a short summary of the bug in here.

So, I have an existing Nest project using mono-repo, and I'd like to add nestia to this. So I followed the instructions, and all this seems to work fine. When I try to start one of the mono-repo apps using

nest start --inspect --debug --watch

It gives several error messages, all similar, like this:

ERROR in ./libs/raja/src/raja.serviceInterface.ts Module build failed (from ./node_modules/ts-loader/index.js): TypeError: Cannot read properties of undefined (reading '0') at get_name (/Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/MethodTransformer.js:47:67) at /Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/MethodTransformer.js:37:22 at /Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/MethodTransformer.js:20:70 at /Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/NodeTransformer.js:13:67 at /Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/FileTransformer.js:22:72 at /Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/FileTransformer.js:16:91 at /Users/***/***-mono-ts/node_modules/@nestia/core/lib/transformers/FileTransformer.js:16:185 at visitArrayWorker (/Users/***/***-mono-ts/node_modules/typescript/lib/typescript.js:93751:49) at visitNodes2 (/Users/***/***-mono-ts/node_modules/typescript/lib/typescript.js:93722:19) at visitEachChildOfClassDeclaration (/Users/***/***-mono-ts/node_modules/typescript/lib/typescript.js:94665:7) @ ./libs/raja/src/raja.serviceImpl.ts 4:32-66 @ ./apps/ingest/src/***/***.module.ts 25:27-68 @ ./apps/ingest/src/main.ts 7:25-60

Sadly, It doesn't tell me what line number to check, and I've checked the files and cannot find anything "offensive" in there either. Also don't know how to debug this further.

Code occuring the bug

I don't know...

Before creating some demonstration code, I though I might have missed something very obvious, plus given that I do not know what triggers any of this, it's rather hard to make any demonstration code.

ChristiaanWillemsen commented 3 weeks ago

Okay, so I can get rid of the error by removing the decorators of the controller functions, like @Get and @Post, or the types variants like @TypedRoute.Post.

Not particularly helpful in solving the issue, but might help narrow down what exactly the issue is?

ChristiaanWillemsen commented 3 weeks ago

Upon further investigation it seem as though the code isn't properly patched, or just not ran though the compiler?

I added some debug statement just before it fails:

symbol SymbolObject {
  flags: 34078720,
  escapedName: 'Promise',
  declarations: undefined,
  valueDeclaration: undefined,
  id: 1333,
  mergeId: 0,
  parent: undefined,
  members: undefined,
  exports: undefined,
  exportSymbol: undefined,
  constEnumOnlyModule: undefined,
  isReferenced: undefined,
  lastAssignmentPos: undefined,
  links: SymbolLinks {
    checkFlags: 1048576,
    declaredType: TypeObject {
      flags: 1,
      checker: [Object],
      id: 6,
      intrinsicName: 'unresolved',
      debugIntrinsicName: undefined,
      objectFlags: 52953088
    }
  }
}

It seems like declarations is empty, which it should probably not be.

So I checked the patching, and that seems to be fine:

yarn prepare
yarn run v1.22.19
$ ts-patch install && typia patch
[!] tsc.js is already patched with the latest version. For details, run: ts-patch check
[!] typescript.js is already patched with the latest version. For details, run: ts-patch check
[+] ts-patch installed!
----------------------------------------
 Typia Setup Wizard
----------------------------------------
Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments.

Therefore, "typia" revives the JSDoc parsing feature by patching "tsc".

This is a temporary feature of "typia", and it would be removed when "ts-patch" being updated.
✨  Done in 0.75s.