Closed Nathan-Nesbitt closed 1 year ago
Hi @Nathan-Nesbitt , the right way to do that import is like this:
import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";
As you can see the export is a default export:
Hope that helps!
@jaydenseric thanks for the quick response, thought this had fixed the original issue but I seem to be back at this again.
Must use import to load ES Module: /<PATH>/backend/node_modules/graphql-upload/graphqlUploadExpress.mjs
or the VS warning Module 'graphql-upload/graphqlUploadExpress.mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
Most likely you are not really writing ESM; you have some sort of dev tooling that transpiles the source ESM you're writing to CJS that actually runs at runtime. In Node.js, ESM can import from ESM or CJS modules, but CJS can't require an ESM module. This is not an issue with graphql-upload
, but rather how Node.js works and your project is setup.
I highly, highly, recommend using ESM in projects both in the source code and at runtime. Your best solution in the long term is to change your build tooling to emit ESM for the runtime code, or else you will get locked out of more and more npm packages over time as they all migrate to pure ESM.
My original issues had to do with #332 and #333 , which led me to the same problem as this comment https://github.com/jaydenseric/graphql-upload/issues/332#issuecomment-1216789254 .
I think I've read through all of the related issues associated with the changes to this library. I've made the changes as suggested in the README and it also doesn't seem to help.
I'm running into the following error when I try to use the new import:
Must use import to load ES Module: /<PATH>/src/backend/node_modules/graphql-upload/graphqlUploadExpress.mjs
The code is as follows for the import:
I've got the following compiler options in
tsconfig.json
and am running the app using
npx nodemon
I'm not really sure what else to try. Any advice for any other things to try?