francescov1 / mongoose-tsgen

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

how to get typescript path alias working? #101

Closed Mike-Van closed 1 year ago

Mike-Van commented 2 years ago

I'm using tsc-alias for alias path in my express application, and when i tried to run mtgen command. it gives this error:

Generating mongoose typescript definitions... !
    Error: Cannot find module 'src/libs/errors'
    Require stack:
    - /Users/m5kev4n/Works/Served/served/apps/api/src/db/schemas.ts
    - /Users/m5kev4n/Works/Served/served/node_modules/mongoose-tsgen/lib/helpers/parser.js
    - /Users/m5kev4n/Works/Served/served/node_modules/mongoose-tsgen/lib/index.js
    - /Users/m5kev4n/Works/Served/served/node_modules/mongoose-tsgen/bin/run
    Code: MODULE_NOT_FOUND

My tsconfig.json:

"compilerOptions": {
      "rootDir": ".",
      "outDir": "dist",
      "baseUrl": "./"
},

My schemas.ts:

import { ERRORS } from 'src/libs/errors' // if i change to '../libs/errors' it works
const customerSchema: CustomerSchema = new Schema({...})

is there any config i can set for mtgen to work with this path alias?

francescov1 commented 2 years ago

Hi @Mike-Van, this tool has not been tested with tsc-alias, so its unlikely to work. Instead, you can use the paths field in tsconfig.json.

Let me know if that resolves the issue for you!

francescov1 commented 1 year ago

@Mike-Van Checking in on my last reply, will close this off soon if I dont hear back