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

Running Lighthouse in Typescript Github Action #16127

Closed
pascalknupper opened this issue Jul 25, 2024 · 1 comment
Closed

Running Lighthouse in Typescript Github Action #16127

pascalknupper opened this issue Jul 25, 2024 · 1 comment
Assignees

Comments

@pascalknupper
Copy link

I´m trying to run Lighthouse programmatically in a custom TypeScript GitHub Action. Unfortunately I cannot get it running after bundling with ncc.

After bundling via npx ncc build src/index.ts -o dist --source-map I run into an issue when running the index.js.

Also I see issues when running the jest tests

SyntaxError: Cannot use import statement outside a module

    > 1 | import lighthouse from 'lighthouse'
        | ^
      2 | import { launch } from 'puppeteer'
      3 |
      4 | export async function runLighthouse(): Promise<void> {

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
      at Object.require (src/lighthouse.ts:1:1)
      at Object.require (src/main.ts:2:1)
      at Object.<anonymous> (__tests__/index.test.ts:5:1)
Error: ENOENT: no such file or directory, open '/home/runner/work/lighthouse-demo-action/lighthouse-demo-action/dist/locales/ar.json'
    at Object.readFileSync (node:fs:448:20)
    at Object.41812 (file:///home/runner/work/lighthouse-demo-action/lighthouse-demo-action/node_modules/lighthouse/shared/localization/locales.js:[3](https://github.com/pascalknupper/lighthouse-demo-action/actions/runs/10089178347/job/27896189514#step:3:4)5:1)
    at __nccwpck_require__ (file:///home/runner/work/lighthouse-demo-action/lighthouse-demo-action/webpack/bootstrap:21:1)
    at file:///home/runner/work/lighthouse-demo-action/lighthouse-demo-action/webpack/startup:[4](https://github.com/pascalknupper/lighthouse-demo-action/actions/runs/10089178347/job/27896189514#step:3:5):1
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:[5](https://github.com/pascalknupper/lighthouse-demo-action/actions/runs/10089178347/job/27896189514#step:3:6))

How do I use the lighthouse npm package correctly in a TypeScript GitHub Action?

This is my demo GitHub Action https://github.com/pascalknupper/lighthouse-demo-action

@connorjclark
Copy link
Collaborator

Closing as out of scope for us, I think.

It does look like the issue may be that your entry point itself is not a module - do you need a package.json that says "type": "module"?

Good luck.

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

3 participants