francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
102 stars 24 forks source link

Error parsing tsconfig.json file in monorepo #159

Open bcheung opened 1 month ago

bcheung commented 1 month ago

Hello! I believe ts-node needs to be upgraded to fix a tsconfig.json issue with monorepos.

I'm getting this error below when I try to run mtgen:

Generating mongoose typescript definitions... !
    Error: Error parsing your tsconfig.json file:
    ENOENT: no such file or directory, open
    '/path/to/monorepo/packages/data/@tsconfig/node20/
    tsconfig.json'

I have a monorepo setup where my tsconfig.json file extends a base tsconfig installed from a package:

{
  "extends": "@tsconfig/node20/tsconfig.json",
...

Using a relative path works in my tsconfig.json:

{
  "extends": "../../node_modules/@tsconfig/node20/tsconfig.json",
...

See a similar issue here was solved with upgrading ts-node to v10.9.2: https://github.com/microsoft/TypeScript/issues/56847#issuecomment-1873956762

francescov1 commented 3 weeks ago

Hey @bcheung thanks for flagging, will try to look into it this weekend

francescov1 commented 3 weeks ago

@bcheung This error is being thrown from the mongoose-tsgen code, right here. This isn't trivial to fix, we're currently using the extends field to find other tsconfig.json files and load in their paths fields, which ensures TS path resolution works. But we would need to resolve aliases fully to find aliased paths.

Could you provide a simple reproduction repo? Would help a lot with fixing

orgads commented 1 week ago

@francescov1 https://github.com/orgads/js-import/tree/tsconfig-node-modules

francescov1 commented 6 days ago

Thanks @orgads will look this weekend