./ts-node.sh runs src/index.ts example and works as expected
./esbuild-register.sh runs src/index.ts but fails with this error:
$ ./esbuild-register.sh
/home/stephen/other/esbuild-register-circular/src/Node.ts:28
class Node extends import_internal.AbstractNode {
^
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/home/stephen/other/esbuild-register-circular/src/Node.ts:3:27)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Module._compile (/home/stephen/other/esbuild-register-circular/node_modules/esbuild-register/dist/node.js:2258:26)
at Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Object.newLoader [as .ts] (/home/stephen/other/esbuild-register-circular/node_modules/esbuild-register/dist/node.js:2262:9)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/home/stephen/other/esbuild-register-circular/src/internal.ts:2:15)
For now I'm able to use ts-node with it's experimental swc transpiler, and that's cool, but I've used esbuild in the past via vitejs, and wouldn't mind sticking with esbuild / esbuild-register, and hopefully just skip ts-node all together.
I'm trying out esbuild-register in a project that uses this pattern:
https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de
To avoid circular dependency issues with TypeScript / JavaScript classes.
I.e. if you have
class Foo extends Bar
, but due to import orderingBar
is undefined whenclass Foo
runs, then you get a runtime error.I've created a reproduction of the issue, using the code from the above article by converted to typescript, here:
https://github.com/stephenh/esbuild-register-circular
There are two scripts:
./ts-node.sh
runssrc/index.ts
example and works as expected./esbuild-register.sh
runssrc/index.ts
but fails with this error:For now I'm able to use ts-node with it's experimental swc transpiler, and that's cool, but I've used esbuild in the past via vitejs, and wouldn't mind sticking with esbuild / esbuild-register, and hopefully just skip ts-node all together.
Thanks!