webhintio / hint

πŸ’‘ A hinting engine for the web

Home Page:https://webhint.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Error [ERR_REQUIRE_ESM] since last update

pereorga opened this issue Β· comments

🐞 Bug report

Description

I'm getting this error since updating to 7.1.9. Tried with both latest node v18.16.0 and v20.3.0 on Mac.

Details

The error is:

$ npx hint https://example.com
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/pere/dev/pccd/node_modules/@hint/utils-network/node_modules/node-fetch/src/index.js from /Users/pere/dev/pccd/node_modules/@hint/utils-network/dist/src/request-async.js not supported.
Instead change the require of index.js in /Users/pere/dev/pccd/node_modules/@hint/utils-network/dist/src/request-async.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/pere/dev/pccd/node_modules/@hint/utils-network/dist/src/request-async.js:4:22)
    at Object.<anonymous> (/Users/pere/dev/pccd/node_modules/@hint/utils-network/dist/src/index.js:24:14)
    at Object.<anonymous> (/Users/pere/dev/pccd/node_modules/hint/dist/src/lib/cli/analyze.js:9:25)
    at /Users/pere/dev/pccd/node_modules/hint/dist/src/lib/cli/actions.js:7:74
    at async /Users/pere/dev/pccd/node_modules/hint/dist/src/lib/cli/actions.js:7:39
    at async Object.execute (/Users/pere/dev/pccd/node_modules/hint/dist/src/lib/cli.js:38:23)
    at async run (/Users/pere/dev/pccd/node_modules/hint/dist/src/bin/hint.js:21:24) {
  code: 'ERR_REQUIRE_ESM'
}

Same here, it seems that the @hint/utils-network dependency version at 1.0.25 introduced this problem, however its been hard to override the nested dependencies that are using utils-version because many many dependencies are pointing to it.

I am also facing the same issue:
Mac(OSX)
Node v16.15.0
"hint": "^7.1.9",

Webhint report

Github

Run npx hint .
  npx hint .
  shell: /usr/bin/bash -e {0}
  env:
    FORCE_COLOR: [1](https://github.com/RileyManda/mocha-algorithms/actions/runs/5226594653/jobs/9441950879#step:5:1)
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/node-fetch/src/index.js from /home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/@hint/utils-network/dist/src/request-async.js not supported.
Instead change the require of index.js in /home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/@hint/utils-network/dist/src/request-async.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/@hint/utils-network/dist/src/request-async.js:4:[2](https://github.com/RileyManda/mocha-algorithms/actions/runs/5226594653/jobs/9441950879#step:5:2)2)
    at Object.<anonymous> (/home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/@hint/utils-network/dist/src/index.js:24:14)
    at Object.<anonymous> (/home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/hint/dist/src/lib/cli/analyze.js:9:25)
    at /home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/hint/dist/src/lib/cli/actions.js:7:74
    at async /home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/hint/dist/src/lib/cli/actions.js:7:[3](https://github.com/RileyManda/mocha-algorithms/actions/runs/5226594653/jobs/9441950879#step:5:3)9
    at async Object.execute (/home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/hint/dist/src/lib/cli.js:38:23)
    at async run (/home/runner/work/mocha-algorithms/mocha-algorithms/node_modules/hint/dist/src/bin/hint.js:21:2[4](https://github.com/RileyManda/mocha-algorithms/actions/runs/5226594653/jobs/9441950879#step:5:4)) {
  code: 'ERR_REQUIRE_ESM'
}
Error: Process completed with exit code 1.

And locally after executing npx hint .
Screen Shot 2023-06-10 at 11 32 55 AM

Reproduced on Ubuntu 22.04 (node v20.2.0)
Screenshot from 2023-06-10 15-03-50

commented

Same, in GH Actions run. Ubuntu 22.04.2 LTS. (ubuntu-latest image)

Same Issue here. Any solutions ?

Same here. webhint is broken on both Windows and Linux for me.

It doesn't look like the new version 7.1.9 itself is the problem. It seems that the issue comes from the new version 1.0.25 of @hint/utils-network which was released together with 7.1.9. There the dependency for node-fetch has been increased from 2.6.7 to the new major version 3.3.1.

image

Going back to 7.1.8 does not help, because it also uses the latest version of @hint/utils-network and thus shows the issue as well!

image

This is really a big issue for us because it breaks the npm install process. Currently its only possible to use npm ci to get our builds running.

A temporary workaround is to override the node-fetch dependency of @hint/utils-network by adding this to your package.json

"overrides": {
  "@hint/utils-network": {
    "node-fetch": "^2"
  }
}

A temporary workaround is to override the node-fetch dependency of @hint/utils-network by adding this to your package.json

"overrides": {
  "@hint/utils-network": {
    "node-fetch": "^2"
  }
}

Thanks @ncausey, That's a very good hint. I'll try it.

Sorry about the lack of updates here, I'll mention this to the Edge DevTools team and see whether this can be investigated sooner rather than later.

thank you everyone for the report, looking into it :-). Please use @ncausey suggestion as a workaround for now.

I just pushed a fix for this and released new version of the packages. Thanks everyone for their patience.

For all who need the workaround quickly. For me ncausey's suggestions did not work exactly as proposed. For me it only worked when installing node-fetch in version 2 for the whole project like this:

"overrides": {
    "node-fetch": "2.6.11"
},