replace ts-node with esbuild?
I just replaced ts-node with esbuild for locally running my Node.js (express.js, TypeScript project) server and it's way faster now. When I remove ts-node from package.json, Knex CLI doesn't run anymore - I gather it has a handful of "registers" that it looks for and is looking for babel as a default, having not found any. If I re-add ts-node, the Knex CLI it runs again. Is there a way to get Knex to run with esbuild-register?
The code for parsing typescript is here: https://github.com/knex/knex/blob/8a50dd7462d40cfa122a233f7fcada24ea39d3ae/bin/cli.js#L105-L111
Knex uses rechoir and intperpret for doing so. I guess the easiest way to implement this would be to allow users supplying custom interpret configs to rechoir.
I guess @abcd-ca use case would already be solved if knex would update "interpret" to the newest version. The newest version supports esbuild out of the box and should automatically select it when ts-node is not available.
I guess @abcd-ca use case would already be solved if knex would update "interpret" to the newest version. The newest version supports esbuild out of the box and should automatically select it when ts-node is not available.
this did not work (I mean updating interpret to latest version)
Any updates here? I've been having some issues with ts-node that doesn't occur with esbuild, so I would like to do that change
PR would be welcome!
@kibertoad From my understanding just the interpret version needs to be bumped. There is already a pr from dependabot: https://github.com/knex/knex/pull/5244
I personally patched my local knex version with the swc/register code from the newest interpret and it works for me. So I highly suspect this will enable esbuild as well.
But I would recommend releasing this as a new major version as the newest interpret version removed some outdated ways of loading typescript. See:
https://github.com/gulpjs/interpret/releases/tag/v3.0.0
Rechoir does not need any changes as knex already uses the newest version.
Also this dependency is quite independet from the rest of the code, so it should not break anything except for the mentioned outdated ways of loading ts.
@lucapasquale @nour-dev You should be able to force knex to use the newest interpret version manually in the mean time via: yarn: https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/ pnpm: https://pnpm.io/package_json#pnpmoverrides npm: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides
Just use this to force it to interpret 3.1.1
Then you have to install esbuild-register: https://github.com/egoist/esbuild-register as esbuild alone will not be enough.
Then it should work.
@mauricedoepke I just use ts-node with swc