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.

ERR_REQUIRE_ESM with Node 18.2

See original GitHub issue

Bug Report

Description

Log4brains init does’nt work and produce following error with node 18.2 clean install.

/usr/local/lib/node_modules/log4brains/node_modules/esm/esm.js:1
const __global__ = 

.../... (long source code)

/usr/local/lib/node_modules/log4brains/node_modules/@log4brains/core/dist/index.module.js:1
Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/log4brains/node_modules/cheerio/lib/esm/index.js not supported.
Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/usr/local/lib/node_modules/log4brains/node_modules/@log4brains/core/dist/index.module.js:1)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/log4brains/node_modules/@log4brains/cli/dist/cli.js:1)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/log4brains/node_modules/@log4brains/cli/dist/index.js:1)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/log4brains/dist/cli.js:1)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/log4brains/dist/main.js:1)
    at Generator.next (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/log4brains/dist/log4brains:5:18) {
  code: 'ERR_REQUIRE_ESM'

Steps to Reproduce

  1. npm y -g log4brains
  2. log4brains init

Expected Behavior

Log4brains should work as expecte…

Context

Simply trying to init log4brains

Environment

  • Log4brains version: 1.0.0-beta.11
  • Node.js version: v18.2.0
  • OS and its version: MacOS X
  • Browser information: NA
npm -g list
/usr/local/lib
├── log4brains@1.0.0-beta.11
└── npm@8.9.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
BjoernAkAManfcommented, May 30, 2022

A possible workaround: Manually downgrade cheerio to 1.0.0-rc.10 works.

I used yarn and the following package.json

{
  "name": "adr",
  "scripts": {
    "adr": "log4brains"
  },
  "dependencies": {
    "log4brains": "^1.0.0-beta.11"
  },
  "resolutions": {
    "cheerio": "1.0.0-rc.10"
  }
}
1reaction
thomvaillcommented, May 30, 2022

Hi!

Fixed in v1.0.0-beta.12 by pinning a fixed version of cheerio directly in the project, as suggested in your workaround ; thank you for this!

Also, to avoid similar incidents in the future, I created this proposal: https://github.com/thomvaill/log4brains/issues/77 I will try to work on this soon

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error [ERR_REQUIRE_ESM]: require() of ES Module not ...
The node-fetch latest version doesn't use the require() syntax to import the package. You need to go to your package.json and type
Read more >
ES modules not supported · Issue #1291 · vercel/pkg - GitHub
I'm getting the following error as soon as the compiled app boots: node:internal/modules/cjs/loader:930 throw err; ^ Error: Cannot find module ...
Read more >
node-fetch Error [ERR_REQUIRE_ESM]: require() of ES ...
The node-fetch error "[ERR_REQUIRE_ESM]: require() of ES Module not supported" occurs because the node-fetch package has been converted to be an ESM-only ...
Read more >
Error [ERR_REQUIRE_ESM]: Must use import to load ES ...
When starting node-red I am getting following error in log file: Welcome to ... nodered/node-red:1.1.2-12 (= Node.js version: v12.18.2) ...
Read more >
Download & Update Node.js to the Latest Version! Node v19 ...
Direct download links to update to the latest Node.js versions: Node v19.0.0 / LTS ... src: print source map error source on demand...
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