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.43k stars 131 forks source link

Getting SyntaxError: Cannot use import statement outside a module only when trying to import graphql-upload module #336

Closed mostaphaamghare closed 1 year ago

mostaphaamghare commented 1 year ago

Getting SyntaxError: Cannot use import statement outside a module only when trying to import graphql-upload module

`` import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";

and when I use this import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.js";

`` I get Error: Package subpath './graphqlUploadExpress.js' is not defined by "exports @jaydenseric

mostaphaamghare commented 1 year ago

This is the screenshot of the error

jaydenseric commented 1 year ago

The correct import is this:

import graphqlUploadExpress from "graphql-upload/graphqlUploadExpress.mjs";

It sounds like something about your project is incorrectly setup relating to the way Node.js ESM and CJS works together:

https://nodejs.org/dist/latest-v18.x/docs/api/esm.html#interoperability-with-commonjs

It's certainly not an issue with graphql-upload; I'm able to import and use the current version fine in projects.

You might find this comment helpful: https://github.com/jaydenseric/graphql-upload/issues/334#issuecomment-1236223984 .