GoogleChrome / chrome-launcher

Launch Google Chrome with ease from node.
https://www.npmjs.com/package/chrome-launcher
Apache License 2.0
1.24k stars 189 forks source link

/Users/sample/node_modules/chrome-launcher/dist/chrome-finder.js:14 const log = require('lighthouse-logger'); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module #299

Closed amrsa1 closed 1 year ago

amrsa1 commented 1 year ago

Recently i start getting the following error when executing my test using webdriverIO

/Users/runner/work/sample/sample/node_modules/chrome-launcher/dist/chrome-finder.js:14
const log = require('lighthouse-logger');
            ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/runner/work/sample/sample/node_modules/lighthouse-logger/index.js from /Users/runner/work/sample/sample/node_modules/chrome-launcher/dist/chrome-finder.js not supported.
Instead change the require of index.js in /Users/runner/work/sample/sample/node_modules/chrome-launcher/dist/chrome-finder.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/runner/work/sample/sample/node_modules/chrome-launcher/dist/chrome-finder.js:14:13)
    at Object.<anonymous> (/Users/runner/work/sample/sample/node_modules/chrome-launcher/dist/chrome-launcher.js:11:22)
    at Object.<anonymous> (/Users/runner/work/sample/sample/node_modules/chrome-launcher/dist/index.js:13:14) {
  code: 'ERR_REQUIRE_ESM'
}

The error message points out that the require() statement in the file chrome-launcher/dist/chrome-finder.js is trying to import an ES module (index.js from lighthouse-logger), but it is not supported in that context.

using dyanmic import() might solve the issue

adamraine commented 1 year ago

See https://github.com/GoogleChrome/lighthouse/issues/15085