Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to ES modules #75

Open
slavamak opened this issue Oct 31, 2023 · 1 comment
Open

Add support to ES modules #75

slavamak opened this issue Oct 31, 2023 · 1 comment

Comments

@slavamak
Copy link

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
Copy link
Author

slavamak commented Nov 1, 2023

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant