question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

const GraphQLUpload = require("graphql-upload/GraphQLUpload.mjs") error but i dont use require

See original GitHub issue

import * as GraphQLUpload from ‘graphql-upload/GraphQLUpload.mjs’; import type { FileUpload } from ‘graphql-upload/processRequest.mjs’;

Error

const GraphQLUploadError [ERR_REQUIRE_ESM]: require() of ES Module CarRent\server\node_modules\graphql-upload\GraphQLUpload.mjs not supported.
Instead change the require of CarRent\server\node_modules\graphql-upload\GraphQLUpload.mjs to a dynamic import() which is available in all CommonJS modules. = require("graphql-upload/GraphQLUpload.mjs") 

Pleace help

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jaydensericcommented, Nov 20, 2022

Have i done this right in this time?

I don’t think so. The TS config looks better, but I’m not sure what you’re doing with the code.

If you want to dynamic import an ES module, perhaps because the surrounding module is CJS, you need to do this:

const { default: GraphQLUpload } = await import("graphql-upload/GraphQLUpload.mjs");

Note that you will run into problems with top level await in a CJS module so you will need to put that in an async function or use .then() syntax.

But you can use a regular import if you have TS configured to emit ES modules:

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

This stuff is just general advice around how native JavaScript works, which is beyond the scope of graphql-upload maintenance. I’m happy to help a little bit with general JavaScript advice, but keep in mind I don’t always have the time.

Here is the MDN article on dynamic import:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

Here is a TypeScript article on ESM in Node.js:

https://www.typescriptlang.org/docs/handbook/esm-node.html

Here is the Node.js docs on ESM:

https://nodejs.org/dist/latest-v19.x/docs/api/esm.html

1reaction
Choco-milk-for-ucommented, Nov 21, 2022

As i understood after deeply consuming these link with documintation i was not very well knowed about webpack and node eco-system as i should (In fact when i was learning about js i didnt even mention about it). The differens between commonjs and ESM is huge and some of modern package decide to use esm now. Thanks for the links i appreciate it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File uploads not working with graphql-upload package #901
When you request the mutation as displayed in the tutorial, the request returns an error not liking the null value in the operation....
Read more >
GraphQL getting error "Upload" is not defined in schema but ...
In my backend app built with NodeJS and GraphQL, I'm getting the below error but I have no clue what does it mean....
Read more >
graphql-upload | Yarn - Package Manager
Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers....
Read more >
graphql-upload - npm
A schema built with separate SDL and resolvers (e.g. using the function makeExecutableSchema from @graphql-tools/schema ) requires the Upload ...
Read more >
Migrating to Apollo Server 4 - Apollo GraphQL Docs
Instead, there's a single ApolloServer class with a single API that all integrations use. In Apollo Server 3, the Apollo Server core team...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found