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.

Error: Must use import to load ES Module

See original GitHub issue

What version of Next.js are you using?

10.2.2

What version of Node.js are you using?

14.16.1

What browser are you using?

Edge

What operating system are you using?

Windows

How are you deploying your application?

local development

Describe the Bug

When importing the react-konva package I get this error

Server Error
Error: Must use import to load ES Module: C:\Users\bucsa\dev\atomic\node_modules\konva\lib\Core.js
require() of ES modules is not supported.
require() of C:\Users\bucsa\dev\atomic\node_modules\konva\lib\Core.js from C:\Users\bucsa\dev\atomic\node_modules\react-konva\lib\ReactKonvaCore.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename Core.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\bucsa\dev\atomic\node_modules\konva\package.json.

The same error was thrown when I tried to import the chessops library but managed to work around that by dynamically importing it when the component loads. Neither that nor importing with next/dynamic could solve the issue with this package though.

Expected Behavior

I expected the components to be imported and not throw an error.

To Reproduce

Install react-konva and konva

import { Stage } from 'react-konva'

const Example = () => {
  return <Stage></Stage>
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:15
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

29reactions
engelmavcommented, Aug 19, 2021

This actually happens intermittently with ReactMarkdown.

12reactions
sidwebworkscommented, Jul 29, 2021

Same issue, any updates?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Importing in Node.js: error "Must use import to load ES Module"
The problem is that Node.js does not currently support import and export natively yet. It is still experimental according ...
Read more >
Error [ERR_REQUIRE_ESM]: Must use import to load ES ...
I just installed the library onto my TypeScript project and I get the following error: Error [ERR_REQUIRE_ESM]: Must use import to load ES ......
Read more >
Must use import to load ES Module - Help - Pipedream
Hi, suddenly my workflow started to fail with the following error: “Must use import to load ES Module”. @germanescobar you can give this...
Read more >
Must use import to load ES Module - Netlify Support Forums
Hello, I have been getting this error on production, but it works fine in my local when I try to preview using netlify...
Read more >
path/node_modules/dot-prop/index.js` and I do not want to ...
Error: [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/node_modules/dot-prop/index.js require() of ES modules is not supported.
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