Closed CamiloGPT closed 1 year ago
Please see the “Exports” section of the readme:
https://github.com/jaydenseric/graphql-upload#exports
The correct way is:
import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";
Note that it's an ESM module, so you can't require
it from a CJS module in your project but you can import
it from an ESM module. That's just how Node.js ESM/CJS compatibility works:
https://nodejs.org/dist/latest-v18.x/docs/api/esm.html#interoperability-with-commonjs
workaround solution for me: 13.0.0v
inorder to use Import, i will have to update module to commonjs, and this would make all of my code where i am using require go on toss.
Is there anyother way for same
@ShilpaM007
inorder to use Import, i will have to update module to commonjs
I think you mean the opposite; you will have to update your modules to ESM.
You can import somewhere in a CJS module if it's a dynamic import:
const { default: graphqlUploadExpress } = await import("graphql-upload/graphqlUploadExpress.mjs");
Just not a regular import:
import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";
Note that CJS modules don't support top level await
, so you will have to either chain a .then()
or call an async function that contains the awaited dynamic import.
Please see the “Exports” section of the readme:
https://github.com/jaydenseric/graphql-upload#exports
The correct way is:
import graphqlUploadExpress.mjs from "graphql-upload/graphqlUploadExpress.mjs";
Note that it's an ESM module, so you can't
require
it from a CJS module in your project but you canimport
it from an ESM module. That's just how Node.js ESM/CJS compatibility works:https://nodejs.org/dist/latest-v18.x/docs/api/esm.html#interoperability-with-commonjs
How can I import and use it in my CommonJS module then?
None of these work... I'm using commonjs with Node 19.
I'm using typescript and this mjs stuff has just made it super hard to use. I have to do stuff like allowJS which I strictly avoided before to ensure typescript was being used. Still I'm not able to get this to work
Same here, been trying to upgrade to the LTS node "18.12.1" using Typescript, but this became a blocker.
@jaydenseric anything you can recommend for TS?
non of these solution work, also using node 18.12.1 is there no way to offer a default export that works?
https://github.com/meabed/graphql-upload-ts seems to be a suitable replacement.
GraphQL not about FileUploading or binary transfer data, so the best solution using other methods for uploading, one of: using apart HTTP endpoint for uploading like example.com/upload
and handle it with your framework express, fastify, etc. with app.use('/upload', (req, res) => { ...
and you don't need this package in fact
P.S. this is just my experience and subjective opinion
Hey! Why is this close? It seems you are not providing the best solution here @jaydenseric Same for me, nothing of this works. Using node v18 with commonJS, as almost every production app in the world.
Edit: I just read your comment here: https://github.com/jaydenseric/graphql-upload/issues/338#issuecomment-1242814452 I think you are right, but man, I hate the JavaScript ecosystem more and more every day.
Thank you for your hard work on this project; I will need to look for an alternative or make the 13.0.0 version work in some way
For those who can't use this package anymore I found the solution using: https://www.npmjs.com/package/graphql-upload-cjs node v18.15 @apollo/server v4 You will need to put a new header if you are using apollo server 4: https://stackoverflow.com/questions/74581070/apollo-client-this-operation-has-been-blocked-as-a-potential-cross-site-request
Hi
I'm using: Node.js v18.0.0 Graphql-upload 16.0.2 Express 4.18.1 Only JavaScript
And show this Error:
Command audit:
I already executed these commands, but they do not solve anything:
how do I fix this error?
Thanks