treosh / lighthouse-ci-action

Audit URLs using Lighthouse and test performance with Lighthouse CI.
MIT License
1.15k stars 81 forks source link

Support ES Modules / Bump node version #100

Closed mxkyb closed 2 years ago

mxkyb commented 2 years ago

Hello,

first of all, great project!

There is a problem when using ES Modules for puppeteer scripts like this:

# action.yml
      - name: Audit
        uses: treosh/lighthouse-ci-action@v8
        with:
          urls: https://some.url
          configPath: ./lighthouserc.json
// lighthouserc.json
{
    "ci": {
        "collect": {
            "puppeteerScript": "index.cjs"
        }
    }
}
// index.cjs
module.exports = (...args) => {
    return import('./index.js').then((module) => {
        return module.default(...args);
    });
};
// index.js
import {something} from 'somewhere';

const doThings = async (browser) => {
    await something();
};

export default doThings;

This will result in

Error: Not supported
at module.exports ...

I think the problem comes from here, because es modules were still experimental in node 12. https://github.com/treosh/lighthouse-ci-action/blob/main/action.yml#L35