jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.42k stars 131 forks source link

Graphql-upload not working for Type-Graphql based project But old version of graphql-upload (.js) version works #381

Closed isarojdahal closed 6 months ago

isarojdahal commented 6 months ago

I have configured all the configs required for new .mjs file in tsconfig.json but still there is issue; as

[ERROR] 12:55:18 Error: require() of ES Module /backend/nodemodules/.pnpm/graphql-upload@16.0.2@types+express@4.17.17_graphql@16.8.1/node_modules/graphql-upload/GraphQLUpload.mjs not supported. Instead change the require of backend/nodemodules/.pnpm/graphqlupload@16.0.2@types+express@4.17.17_graphql@16.8.1/node_modules/graphql-upload/GraphQLUpload.mjs to a dynamic import() which is available in all CommonJS modules.

On my research , I have found that node-fetch had upgraded that's why, its not working.

jaydenseric commented 6 months ago

I'm sorry but I don't think I will be able to help much with this because it involves debugging your project and its dependencies. If I could offer an obvious solution from the clues you've provided I would; but nothing jumps out at me.

If you have the correct project setup you should be able to get the latest version of graphql-upload working fine in a TypeScript project; I do so successfully at work in our project.

I suspect that whatever dependency you are using to build your schema is generating CJS modules instead of ESM, and they are attempting to require the GraphQLUpload scalar which is ESM, which is an invalid thing to do. You mentioned TypeGraphQL; so the logical place to start is to check it's working correctly with ESM. It looks like they have bugs to be fixed on their end:

https://github.com/MichalLytek/type-graphql/issues/1442

If you figure out a solution, feel free to report it here in case it helps anyone googling a similar issue.