francescov1 / mongoose-tsgen

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

Error parsing tsconfig.json file in monorepo #159

Closed bcheung closed 2 months ago

bcheung commented 3 months 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 months ago

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

francescov1 commented 3 months 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 3 months ago

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

francescov1 commented 2 months ago

Thanks @orgads will look this weekend

francescov1 commented 2 months ago

Sorry the for delay, will try to get to this shortly

francescov1 commented 2 months ago

@bcheung @orgads fix is live in v9.4.3 🚀 path resolving and tsconfig parsing is much more robust now, using the node resolve module and not overwriting the user's compilerOptions.module field

francescov1 commented 2 months ago

Noticed a bug with tsconfig parsing of certain other compilerOptions.module options (not with your use case but other use cases), so pushed a further fix in v9.4.4. Try that one out, it should work for you as well.