I'm trying to run a migration. My Knexfile is written in Typescript with some path aliases coming from tsonfig.json, but Knex fails with Cannot find module '@foo-alias/bar-module'. What do I need to change in the way I'm running Knex migrate or in my TS configuration to make that work?
I've tried using something like this, per some threads I've seen online, but no dice:
TS_NODE_PROJECT=tsconfig.knexfile.json knex migrate:latest
{
"compilerOptions": {
...a bunch of compiler options here
"paths": {
"@foo-alias/*": ["src/foo/*"]
}
},
"exclude": ["node_modules"]
}
I just needed to register the tsconfig paths like so:
ts-node -r tsconfig-paths/register ./node_modules/.bin/knex --knexfile ./knexfile.ts "migrate:latest"
if you dont want to modify the npm scripts
Add this to the top of the knexfile file
require('tsconfig-paths/register');
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