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
tslib.__extends called on undefined prototype #14734
Comments
You are dealing with a circular dependency. TypeScript can statically identify the shape of everything, therefore it is fine, but it seems WebPack (you module loader of choice) is not resolving the circular dependency effectively at runtime. I suspect that WebPack is attempting to instantiate module When they are in the same module, |
Thanks @kitsonk, makes sense. I wasn't sure at first if this was a TypeScript or Webpack issue. I'll move this over there and close it here for now. |
I'd like to add to @kitsonk's excellent explanation that you might be able to workaround this by changing the export order of some of your barrels/modules. I can't explain it well in generic terms since it really depends on how you organized your barrels and where your webpack entry points are, but a good rule of thumb would be to always export higher level classes at the bottom and its dependencies at the top. |
Thanks for your imput @cvsguimaraes. In the end it all came down to the fact that TypeScript assumes that module imports do not have side effects. See here for more info: webpack/webpack#4520 (comment) |
Hi, We have the same error. Currently it is difficult to find the cycle and I was hoping this could be fixed or the error could be improved. But it's unclear to me if this is now a Webpack or typescript issue? (it's closed on both repos) |
@304NotModified See this comment from webpack author on the issue. |
i am facing the same issue and cant find exact root cause of this error. |
As stated in the comment that @cvsguimaraes linked to, this isn't either a TypeScript or WebPack issue. It is an effect of how ES6 modules are parsed. Circular dependencies will be your downfall and arguably a bad design decision. They are fragile. TypeScript is not disallowing it, which I guess would be the only argument, in that when you have an import order issue that cannot be resolved. |
@kitsonk all i am doing is extending classes to base api class. Does this mean i should change the code and not use class extends? |
This particular issue has to do with circular references, where
Clearly that can' be the case, if you are encountering this issue. |
What would be the way to fix it ? change the imports or not use extend and use it as
|
You are giving one line of code and saying how do I fix it? when you have even indicated what the problem is. The code you are quoting doesn't even reference the code at the top of this issue. You should be asking "how do I" questions on Gitter or StackOverflow, providing an appropriate level of information on what the problem is. |
So i am extending providers with base api provider. HistoryRequestProvider is one of the provider extending to ApiService. there are around 10+ providers which extend to ApiService.
and this is the error i get |
The issue tracker is for tracking issues with TypeScript itself, not issues with user code. |
TypeScript Version: 2.2.1
Code
To make things simple, here's a repo to easily reproduce this: https://github.com/jsayol/typescript-issue-14734
And load index.html in the browser.
a.ts:
b.ts
index.ts
Expected behavior:
Seeing "B hello" logged in the console.
For reference, putting all the code in a single file generates the correct output:
Actual behavior:
This is the generated
b.js
, where the problem is:The text was updated successfully, but these errors were encountered: