Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_REQUIRE_ESM with Node 18.2 #74

Closed
nmortier12 opened this issue May 21, 2022 · 5 comments · Fixed by #76
Closed

ERR_REQUIRE_ESM with Node 18.2 #74

nmortier12 opened this issue May 21, 2022 · 5 comments · Fixed by #76
Labels
bug Something isn't working

Comments

@nmortier12
Copy link

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
@nmortier12 nmortier12 added the bug Something isn't working label May 21, 2022
@raikbitters
Copy link

The same in Node 16 and 14

@AmsterGet
Copy link

This happened after the release of the new RC version of cheerio with ESM modules support.

@BjoernAkAManf
Copy link

BjoernAkAManf commented 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"
  }
}

@raikbitters
Copy link

We solved it using npm ci and run npx run log4brain

Our package.json

{
  "name": "adl",
  "version": "1.0.0",
  "dependencies": {
    "log4brains": "latest",
    "cheerio": "1.0.0-rc.10"
  }
}

@thomvaill
Copy link
Owner

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: #77
I will try to work on this soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants