Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with import order / circular dependencies #62

Open
stephenh opened this issue Dec 30, 2021 · 0 comments
Open

Issue with import order / circular dependencies #62

stephenh opened this issue Dec 30, 2021 · 0 comments

Comments

@stephenh
Copy link

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 ordering Bar is undefined when class 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 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.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant