Shopify / lighthouse-ci-action

MIT License
100 stars 50 forks source link

Add support to ES modules #75

Open slavamak opened 10 months ago

slavamak commented 10 months ago

Describe the bug

I get an error for /github/workspace/setPreviewCookies.js

Steps to reproduce

  1. Add type: "module" to package.json file
  2. Push the changes to repo for trigger github action

Logs

Run shopify/lighthouse-ci-action@v1.1.1
==============================
Configuring Lighthouse CI
Fetching product handle
Using gift-card
==============================
Running Lighthouse CI
✅  .lighthouseci/ directory writable
✅  Configuration file found
✅  Chrome installation found
✅  GitHub token set
Healthcheck passed!

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /github/workspace/setPreviewCookies.js
require() of ES modules is not supported.
require() of /github/workspace/setPreviewCookies.js from /.node/lib/node_modules/@lhci/cli/src/collect/puppeteer-manager.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename setPreviewCookies.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /github/workspace/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at PuppeteerManager.invokePuppeteerScriptForUrl (/.node/lib/node_modules/@lhci/cli/src/collect/puppeteer-manager.js:107:20)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Object.runCommand (/.node/lib/node_modules/@lhci/cli/src/collect/collect.js:[24](https://github.com/sleeksetup/spirit/actions/runs/6708996679/job/18231056912#step:4:25)0:7)

    at async run (/.node/lib/node_modules/@lhci/cli/src/cli.js:103:7)
slavamak commented 10 months ago

As a temporary solution, I remove the "type" key before the lighthouse-ci-action step

 runs-on: ubuntu-latest
 steps:
   - uses: actions/checkout@v3
+  - name: Remove type from package.json
+    run: |
+      jq 'del(.type)' package.json > temp.json && mv temp.json package.json
   - name: Lighthouse
     uses: shopify/lighthouse-ci-action@v1.1.1
     with: