In a next.js project, I am trying to add knex. I've installed sqlite3, knex, ts-node (because I saw it whilst googling). Then I ran
npx knex init -x ts
and changed the generated knexfile.ts to have
require("ts-node/register");
module.exports = {
development: {
client: "sqlite3",
connection: {
filename: "./dev.sqlite3"
//I also tried using absolute path (same thing
},
debug: true,
useNullAsDefault: true,
},
....
};
I read that you need to include ts-node/register, I tried import 'ts-node/register' but the same thing, nothing works.
In package.json I have this script
"knex": "./node_modules/.bin/knex --knexfile database/knexfile.ts migrate:make"
I also used knex directly, and nothing. It complains about the require, if you remove the require it complains about needing the ts-node/register, if you import it it doesn't accept import, it doesn't accept module.exports it doesn't accept export default
If I change the file to javascript (knexfile.js) it generates javascript files