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 [ERR_REQUIRE_ESM]: Must use import to load ES Module

See original GitHub issue

Hi, I’m having an issue importing the library using Next.js.

NPM version: 6.14.11 Node version: v14.16.0 Next.js version: v9.4

Error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/fraps/Coding/looselyhub/looselyhub/node_modules/direction/index.js
require() of ES modules is not supported.
require() of /home/fraps/Coding/looselyhub/looselyhub/node_modules/direction/index.js from /home/fraps/Coding/looselyhub/looselyhub/node_modules/@glideapps/glide-data-grid/dist/js/data-grid/data-grid-lib.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 index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/fraps/Coding/looselyhub/looselyhub/node_modules/direction/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/fraps/Coding/looselyhub/looselyhub/node_modules/@glideapps/glide-data-grid/dist/js/data-grid/data-grid-lib.js:19:41)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/fraps/Coding/looselyhub/looselyhub/node_modules/@glideapps/glide-data-grid/dist/js/data-editor/data-editor.js:22:20)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32) {
  code: 'ERR_REQUIRE_ESM'
}

How I’m importing:

import DataEditor from '@glideapps/glide-data-grid' 
import { DataEditorContainer, GridColumn, GridCell } from '@glideapps/glide-data-grid'; 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lukekimcommented, Oct 19, 2021

I had the same issue. The latest version of direction is 2.0.0, which seems generate the same error above.

When I downgraded to direction@1.0.4 as @itchii-06 commented, everything worked as expected.

0reactions
dvdsglcommented, Nov 12, 2021

The README has been updated with direction@1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The error [ERR_REQUIRE_ESM]: require() of ES Module not supported. Instead change the require of index.js to a dynamic import() which is available in...
Read more >
Must use import to load ES Module · Issue #28 · sindresorhus ...
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/salty/Documents/src/youtu-bu/node_modules/ky-universal/index.js require() ...
Read more >
Error [ERR_REQUIRE_ESM]: How to use es6 modules in ...
All you have to do is adding the flag --experimental-modules that supports the new es6 import/export statement also the order is important ...
Read more >
Error ERR REQUIRE ESM | Must use import to load ES Module
JS - JavaScript. Error ERR REQUIRE ESM | Must use import to load ES Module. 15K views 1 year ago. Sagar S. Sagar...
Read more >
Must use import to load ES Module - Netlify Support Forums
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/node_modules/@steeze-ui/heroicons/index.js require() of ES modules is ...
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