MODULE_NOT_FOUND error when using Prisma with ModuleAliases

17 views Asked by At

I wanted to add a module alias for prisma.ts, to use

import prisma from '@prisma'

instead of a relative path import.

I tried it by adding this to the tsconfig.json:

"paths": {
    "@services/*": ["lib/services/*"],
    "@prisma": ["lib/db/prisma"]
},

and adding this to the package.json:

"_moduleAliases": {
    "@services": "dist/lib/services",
    "@prisma": "dist/lib/db/prisma"
},

The service part works perfectly and the IDE finds the prisma as well, but after compiling I've got a MODULE_NOT_FOUND error

Error when loading '/opt/bot/dist/listeners/api/match.js': Error: Cannot find module '/opt/bot/dist/lib/db/prisma/client'

But if I remove the alias and import it with it's relative path the compiler finds it easily.

What could be the problem with the aliases?

0

There are 0 answers