mongoose-tsgen icon indicating copy to clipboard operation
mongoose-tsgen copied to clipboard

how to get typescript path alias working?

Open Mike-Van opened this issue 2 years ago • 2 comments

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?

Mike-Van avatar Jul 17 '22 04:07 Mike-Van

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 avatar Jul 17 '22 13:07 francescov1

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

francescov1 avatar Oct 21 '22 16:10 francescov1