knex icon indicating copy to clipboard operation
knex copied to clipboard

replace ts-node with esbuild?

Open abcd-ca opened this issue 3 years ago • 8 comments

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?

abcd-ca avatar May 27 '22 18:05 abcd-ca

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.

mauricedoepke avatar May 29 '22 21:05 mauricedoepke

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.

mauricedoepke avatar May 29 '22 22:05 mauricedoepke

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)

noor-tg avatar Oct 26 '23 04:10 noor-tg

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

lucapasquale avatar Apr 04 '24 15:04 lucapasquale

PR would be welcome!

kibertoad avatar Apr 04 '24 15:04 kibertoad

@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.

mauricedoepke avatar Apr 04 '24 16:04 mauricedoepke

@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 avatar Apr 04 '24 16:04 mauricedoepke

@mauricedoepke I just use ts-node with swc

noor-tg avatar Aug 01 '24 20:08 noor-tg