close

[Solved] Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported in nodejs. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported occurs?

I am facing following error.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/user/LiveStreamProject/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.

How To Solve Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported?

  1. How To Solve Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported?

    To Solve Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported To solve this error you just need to specify "type":"module" in package.json. second solution is While You are running your file Just Use this flag --input-type=module when running the file and third one is Follow this step to solve this issue Remove the esm package. Add “type”: “module” to your package.json. And that’s it. Then when you run node server.js it should work.

  2. Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported

    To Solve Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: require() of ES modules is not supported To solve this error you just need to specify "type":"module" in package.json. second solution is While You are running your file Just Use this flag --input-type=module when running the file and third one is Follow this step to solve this issue Remove the esm package. Add “type”: “module” to your package.json. And that’s it. Then when you run node server.js it should work.

Solution 1: specify “type”:”module” in package.json

To solve this error you just need to specify "type":"module" in package.json.

Solution 2: Use this --input-type=module when running the file

While You are running your file Just Use this flag --input-type=module when running the file

Solution 3: Follow this step.

Follow this step to solve this issue.

  1. Remove the esm package.
  2. Add "type": "module" to your package.json.
  3. And that’s it. Then when you run node server.js it should work.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read