-
Notifications
You must be signed in to change notification settings - Fork 17
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 generated code on circular dependency #42
Comments
Usually in TypeORM you can simply use |
Do you mean passing the string instead of the function, right? Suggested here - typeorm/typeorm#4190
The relationship is referenced by string, but the Reflect.metadata is doing that |
Didn't know about the string version, however the problem here is in the type definition ( I may suggest to type |
I gave that a try, but the generated code doesn't change at all
Transpiled code
|
Changing it to |
Update: I also notice that my Babel/Webpack is outputting a different result between dev and prod. And it seems like it works fine if Webpack bundles my barrel file correctly (a rollup index file for all of my db models). I put more details of my question here - https://stackoverflow.com/questions/65102724/inconsistent-webpack-with-babel-output-in-using-a-barrel-file-between-dev-and-pr |
@kelvien any luck with this? I see you're using nextjs too |
Hey @mmahalwy, one alternative was to put the models with circular dependency into one file, it's not the most ideal approach, but I can't seem to find a better solution other than fixing the transpiler itself. |
@kelvien oh yeah, but that could get really messy really quickly 😓 |
Got the same issue with nextjs, still no solution ? =( |
Probably TypeScript is smarter here while generating decorators and is wrapping them in functions. I'll see if this is solvable using this plugin alone, or if the problem arises from babel decorators generation process |
Issue
It seems like the generated code through this Babel plugin raises an issue in using a variable before it is initialized.
I did see the same issue reported by someone here - https://stackoverflow.com/questions/61297622/typescript-metadata-reflection-references-other-classes-before-they-are-defined, but I don't think it's closed with a solution to the core problem.
Context
I'm using TypeORM for my interaction with a database. And in this example I defined two entities that need each other (a one-to-one relationship)
I provide a minimal reproduction code in this repo - https://github.com/kelvien/repro-next-circ-metadata/
It seems like you've mentioned this as one of the pitfalls. I'm just wondering if there is an alternate way in solving this issue, and perhaps a longer term solution to this.
The text was updated successfully, but these errors were encountered: