-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Cannot access 'resolvers' before initialization #1255
Comments
This seems like an issue with next.js, I only have this error when trying to use API route as the endpoint of the graphql API. But if I just simply write a script like this
It works as expected. But I am curious why using API route will yield this initialization error. |
I think it's because of the way NextJS bundle the code. See #55 and other related issues. |
Thanks @MichalLytek, regarding #55, which solution do you think might be a potential fix for this? |
I tried using the babelrc as follows:
But still get the same error. |
I think the error is caused by NextJS trying to bundle the whole API into a single file. This causes issues when you have references between your types (classes). The one below is not created yet, etc. |
@MichalLytek I see, does that mean if we are using NextJS we have to set But setting this I will not be able to reuse the types generated, and got errors like:
|
The transpiled code behaves just like a normal source code - you can import the classes, use them as values or as types. |
Closing for a housekeeping purposes 🔒 |
I was trying to follow the typegraphql-prisma tutorial but got some unexpected error. To repro this:
.prisma
file add:Then I got error:
Cannot access 'resolvers' before initialization
.By tsconfig is as follows:
NOTE:
This error only happens when I generate typegraphql files with customized output folder, and when the generated code is emitted as a raw TS source code. If I don't set
output
in.prisma
file, and useimport { resolvers } from "@generated/type-graphql";
with the transpiled code, there will not be such error.However, I have to use the raw TS source code since I have some customized resolver with need the Types generated for
@Args
.The text was updated successfully, but these errors were encountered: