Make sure you have ts-node installed: npm install ts-node
This creates a .ts file in migrations directory
npm run knex:migrate:make -- some-migration-name
npm run knex:migrate:latest
npm run knex:migrate:rollback
knexfile.ts
requiresrequire('ts-node/register');
to work.- ES6/ES2015 module syntax does not work in knexfile or in any files that it
require()
s
I've this problem to use your soluction
internal/bootstrap/switches/does_own_process_state.js:115
rawMethods.chdir(directory);
^
Error: ENOENT: no such file or directory, chdir '/home/rafael/Projects/exemples/rest-api-typescript' -> '/home/rafael/Projects/exemples/rest-api-typescript/src/database'
at process.wrappedChdir [as chdir] (internal/bootstrap/switches/does_own_process_state.js:115:14)
at initKnex (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/knex/bin/cli.js:61:13)
at Command. (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/knex/bin/cli.js:167:24)
at Command.listener (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/commander/index.js:370:29)
at Command.emit (events.js:321:20)
at Command.parseArgs (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/commander/index.js:892:12)
at Command.parse (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/commander/index.js:642:21)
at Liftoff.invoke (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/knex/bin/cli.js:353:13)
at Liftoff.execute (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/liftoff/index.js:201:12)
at module.exports (/home/rafael/Projects/exemples/rest-api-typescript/node_modules/flagged-respawn/index.js:51:3) {
errno: -2,
code: 'ENOENT',
syscall: 'chdir',
path: '/home/rafael/Projects/exemples/rest-api-typescript',
dest: '/home/rafael/Projects/exemples/rest-api-typescript/src/database'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] knex:migrate:make:
knex --knexfile src/database/knexfile.ts -x ts migrate:make "users"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] knex:migrate:make script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/rafael/.npm/_logs/2020-01-30T19_03_08_678Z-debug.log