Skip to content

Add support to ES modules #75

@slavafyi

Description

@slavafyi

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions