nestia icon indicating copy to clipboard operation
nestia copied to clipboard

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

Open ChristiaanWillemsen opened this issue 1 year ago • 2 comments

Summary

Write a short summary of the bug in here.

  • SDK Version: [email protected], @nestia/core@^3.17.0, @nestia/fetcher@^3.17, typia@^6.11.0
  • Expected behavior: I don't know, never had it working ;)
  • Actual behavior: When running the project, on several files I get this error: TypeError: Cannot read properties of undefined (reading '0')

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 avatar Oct 08 '24 13:10 ChristiaanWillemsen

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 avatar Oct 09 '24 13:10 ChristiaanWillemsen

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.

ChristiaanWillemsen avatar Oct 09 '24 14:10 ChristiaanWillemsen

I have the same issue when trying to run jest tests.

TypeScript v5.8.2

vkartaviy avatar Apr 04 '25 00:04 vkartaviy

Needs reproducible repo

samchon avatar Apr 06 '25 11:04 samchon

Close due to no reproducible repo providing.

samchon avatar Aug 08 '25 16:08 samchon