-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
fix(prisma): resolve several issues with prisma generate for ESM #2741
fix(prisma): resolve several issues with prisma generate for ESM #2741
Conversation
@@ -15,7 +16,9 @@ function createDecorator(name: string, args: string[]): DecoratorStructure { | |||
|
|||
export function transformFieldToDecorators(field: DmmfField, ctx: TransformContext): DecoratorStructure[] { | |||
const hasCircularRef = isCircularRef(field.model.name, field.type, ctx); | |||
|
|||
if (isEsm() && hasCircularRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in this case, a lot of decorators won't be generated...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know howto fix following issue in esm , any sugguest?
../tsed/packages/orm/prisma/lib/esm/.schema/models/MessageModel.js:129
__metadata("design:type", ConversationModel)
^
ReferenceError: Cannot access 'ConversationModel' before initialization
at ../tsed/packages/orm/prisma/lib/esm/.schema/models/MessageModel.js:129:31
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Node.js v20.11.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should wrap the ConversationModel into an arrow function instead adding it directly in the concerned decorator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eg: Property(() => ConversationModel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generate MessageModel.js is already in the form of a function.
...
__decorate([
Property(() => ConversationModel),
Required(),
__metadata("design:type", ConversationModel)
], MessageModel.prototype, "conversation", void 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with the details here, so I wonder if you could help implement it. I can help you verify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed :) @vangie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried in my project,everything is OK。@Romakita
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect go merge :D
0320aec
to
cc7dc01
Compare
1. Correct the generated 'lib/esm/index.js' file's path. 2. Workaround for 'ReferenceError: Cannot access 'xxx' before initialization' caused by esm circular ref.
cc7dc01
to
9ac425d
Compare
9ac425d
to
22e5e0d
Compare
🎉 This PR is included in version 7.75.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Information
Todos