I would like to use custom paths from Typescript.
In my project, I switched from:
import { User } from 'src/entities/user.entity';
to:
import { User } from '@entities/user';
Into tsconfig.json
I put :
"paths": {
"@entities/*": ["src/entities/*.entity.ts"]
}
When I run npm run start:dev
(=nodemon), I have this error:
Error: Cannot find module '@entities/user'
In debug mode, npm prints out:
looking for "@entities/user" in [".../node_modules", ".../node_modules"]
It is never looking for in the folder "src/entities" or something similar.
Maybe it is because thoses paths are not interpreted when running ? Should I create some kind of bootstrap like here ?
FIX
The issue came from nodemon.json
:
I had to replace:
{
"watch": ["dist"],
"ext": "js",
"exec": "node dist/main"
}
By:
{
"watch": ["src"],
"ext": "ts",
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
Now TypeORM knows where to find the entities in development env.
FIX
The issue came from nodemon.json:
I had to replace:
{
"watch": ["dist"],
"ext": "js",
"exec": "node dist/main"
}
By:
{
"watch": ["src"],
"ext": "ts",
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
Now TypeORM knows where to find the entities in development env.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With