Open karlhorky opened 7 months ago
lighthouserc.cjs
is actually supported (https://github.com/GoogleChrome/lighthouse-ci/pull/650), but looks like the docs need to be updated :/. This at least covers case 3 so you don't need to use a JSON file, but the other cases would still be nice to have.
+1 -- I have a custom Lighthouse config in my lighthouserc.js
:
module.exports = {
ci: {
// [snip]
settings: {
configPath: './lighthouse-config.js',
}
},
};
Trying const constants = require('lighthouse/core/config/constants.js')
in lighthouse-config.js
doesn't work because those are ESM modules. import
isn't supported (this issue), and haven't been able to get dynamic import()
to work with CJS! 😖
Update: Renaming to lighthouse-config.mjs
and using regular import/export
does work!
Is your feature request related to a problem? Please describe.
Currently, running
lhci autorun
in an ESM project causesERR_REQUIRE_ESM
failures, because the configuration file is beingrequire()
d:Describe the solution you'd like
It would be nice to be able to use Lighthouse CI in ESM projects (eg. projects specifying
"type": "module"
inpackage.json
):lighthouserc.js
when"type": "module"
specified inpackage.json
lighthouserc.mjs
for CommonJS projects who want to opt in to ESM in this one filelighthouserc.cjs
for ESM projects who want to stay with the current CommonJS config~ done in https://github.com/GoogleChrome/lighthouse-ci/pull/650 and https://github.com/GoogleChrome/lighthouse-ci/pull/975The currently supported configuration files:
.lighthouserc.js
lighthouserc.js
.lighthouserc.json
lighthouserc.json
.lighthouserc.yml
lighthouserc.yml
.lighthouserc.yaml
lighthouserc.yaml
Describe alternatives you've considered
Not having ESM support (having to use JSON config files in ESM projects)
Additional context
Lighthouse itself switched to ESM in this umbrella issue managed by @connorjclark