-
-
Notifications
You must be signed in to change notification settings - Fork 132
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 load v16.0.1 #332
Comments
This duplicates a lot of other issues. Please see the changelog or GitHub release descriptions for the breaking changes in the past few major versions. Pay particular attention to the migration instructions for imports. |
Also, uninstall |
Well, sorry for the duplicates but I saw some issues here talking about files .js, I guess for v14/15, here it's .mjs. import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
console.log(graphqlUploadExpress); // undefined then in my nestjs resolver import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
// Did you remove the ts type FileUpload? Lets try GraphQLUpload then
async uploadFile(
// ...
@GqlArgs('file', { type: () => GraphQLUpload }) { createReadStream, filename, mimetype }: GraphQLUpload,
) { Error: I'm quite lost. |
I don't know what build tooling you have setup (I don't use Nest.js), but it sounds like it is transpiling the ESM module into a CJS module, then running that which is problematic because it's a limitation of Node.js that a CJS module can't require an ESM module. This stuff is beyond the scope of Regarding the TypeScript type // Within a TypeScript module.
import type { FileUpload } from "graphql-upload/processRequest.mjs"; // Within a JavaScript module.
/** @type {import("graphql-upload/processRequest.mjs").FileUpload} */ Note that it might not be the same as whatever the type of the same name from I've been working on a few updates to the readme to make some things clearer like how to import the type |
I don't know why you closed this issue but I got the same error. |
@vincentwinkel I have same issue. |
Your issues likely relate to Nest.js knowingly not supporting importing ESM modules, please raise more issues in their repo since they immediately closed and locked this one last year: It's up to them to support their users, not me. The format of my package is perfectly valid. It's a bad idea to get locked into frameworks, instead use libraries to compose your own systems that you understand and have control over. Learn how the runtime environment actually works instead of hiding behind multiple layers of build tools and "magic". Why anyone would choose to use a framework that is incapable of working with the standard JavaScript module format (ESM) is beyond me! If you don't fix this in your projects, you will run into problems trying to use any of the growing number of packages that are published as ESM. I'm not being unreasonable here; https://github.com/graphql/graphql-js/releases/tag/v17.0.0-alpha.1 |
Well, I am not using nestjs. |
@is-jaduda then you don't have the exact same issue as the comment you were referring too. Lots of different project setups can result in the same error message. |
@jaydenseric Are you aware of any workarounds to this? Is there a way that you could publish it, so that us nest.js developers can benefit from your great package? We depend on a lot of open-source projects, and usually just import like this: It's also interesting how there are many articles referencing your library, and they seem to work just fine with Nest.js:
They just don't anymore 🙁 (basically how you did it in version 13) - it seems to break from version 14 upwards. |
Me changing the
No, Nest.js should fix Nest.js bugs or else users will have to abandon it as it will no longer be fit for purpose as many important npm packages are being published in standard ESM format. Regarding all those articles/tutorials, they are years old and it's not reasonable to expect their code examples to still work the same. I've published new versions of |
No worries, I'll find another approach. Thanks for your time. |
Did you find another approach @simplenotezy ? It would be helpful to have it here if you did :) |
Hey! Ended up using a standard REST API endpoint for the upload |
Nice! Thanks for replying :) Can you have the upload field within the Input Type with the other fields of a form, or that way you are always forced to upload a file alone? |
If anyone is struggling with this, I found a solution for this: within some async function just call const { default: graphqlUploadExpress } = await (eval(
`import('graphql-upload/graphqlUploadExpress.mjs')`,
) as Promise<typeof import('graphql-upload/graphqlUploadExpress.mjs')>); |
@bnussman I am using the latest version of |
This Initially, I imported the required modules by employing the following syntax: It is noteworthy that in version 16 of graphql-upload, the presence of index.js has been deprecated. This change in module structure appears to be the root cause of the encountered error. If the previously mentioned resolution method does not yield successful results, an alternative approach would be to revert to graphql-upload version 13. When examining the available package versions in the npm repository, I observed that version 16 possesses the least number of downloads. In contrast, versions 13 and 11 appear to be more commonly adopted by the community. Therefore, considering these alternative versions could prove beneficial if further difficulties persist. |
Holly jesus... Why don't use typescript like any other library? |
This project does use TypeScript, see how Line 89 in f24d71b
At work I use As to why all my open source packages are published with baked in TypeScript types via JSDoc comments, instead of seperate type definition files, see: |
In a TS project using graphql-upload v16.0.1, when I
npm run dev
:Setup:
The text was updated successfully, but these errors were encountered: