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

TypeError: Cannot read properties of undefined (reading 'score') #240

Closed
nmcltpx opened this issue Sep 18, 2024 · 3 comments
Closed

TypeError: Cannot read properties of undefined (reading 'score') #240

nmcltpx opened this issue Sep 18, 2024 · 3 comments

Comments

@nmcltpx
Copy link

nmcltpx commented Sep 18, 2024

Describe the bug

When running Unlighthouse as CLI or CI on my local machine, it progresses well for quite a while, and then fails with the following error: (note: user and site details anonymised)

[error] [Unlighthouse] Failed to run lighthouse for route Command timed out after 360000 milliseconds: node /path/to/unlighthouse/node_modules/@unlighthouse/core/dist/process/lighthouse.mjs --cache=true --routeReport={"route":{"url":"https://www.domain.uk/path/path/path/page"},"artifactPath":"/path/to/unlighthouse/.unlighthouse-ci/reports/reportdir/reportdir2/reportdir3/reportpart"} --lighthouseOptions={"onlyCategories":["performance","accessibility","best-practices","seo"],"disableStorageReset":true,"skipAboutBlank":true,"throttlingMethod":"provided","throttling":{"rttMs":0,"throughputKbps":0,"cpuSlowdownMultiplier":1,"requestLatencyMs":0,"downloadThroughputKbps":0,"uploadThroughputKbps":0},"formFactor":"desktop","screenEmulation":{"mobile":false,"width":1350,"height":940,"deviceScaleFactor":1,"disabled":false},"emulatedUserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"} --port=58705

  Timed out
  at timeoutKill (node_modules/execa/lib/kill.js:60:23)
  at Timeout._onTimeout (node_modules/execa/lib/kill.js:72:4)
  at listOnTimeout (node:internal/timers:569:17)
  at process.processTimers (node:internal/timers:512:7)
file:///path/to/unlighthouse/node_modules/@unlighthouse/core/dist/index.mjs:986
          if (response.report.score)
                              ^

TypeError: Cannot read properties of undefined (reading 'score')
    at file:///path/to/unlighthouse/node_modules/@unlighthouse/core/dist/index.mjs:986:31

This is my config (domain anonymised):

import { defineConfig } from 'unlighthouse'

// Is command unlighthouse or unlighthouse-ci?
const isCI = process.env.CI === 'true';

export default defineConfig({
  puppeteerOptions: {
    timeout: 18000000,
    headless: true,
    dumpio: false,
  },
  puppeteerClusterOptions: {
    concurrency: 1,
    timeout: 180000000,
  },
  server: {
    open: false
  },
  site: 'https://www.domain.uk',
  debug: true,
  cache: true,
  outputPath: isCI ? '.unlighthouse-ci' : '.unlighthouse',
  lighthouseOptions: {
    disableStorageReset: true,
    skipAboutBlank: true,
    throttlingMethod: 'provided',
     throttling:
      { rttMs: 0,
        throughputKbps: 0,
        cpuSlowdownMultiplier: 1,
        requestLatencyMs: 0,
        downloadThroughputKbps: 0,
        uploadThroughputKbps: 0 },
     formFactor: 'desktop',
     screenEmulation:
      { mobile: false, width: 1350, height: 940, deviceScaleFactor: 1, disabled: false },
     emulatedUserAgent:
      'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
  },
  scanner: {
    dynamicSampling: 10,
    skipJavascript: true,
    robotsTxt: false,
    sitemap: false,
    crawler: true,
    samples: 3,
    maxRoutes: 1000,
    device: 'mobile',
    throttle: false,
    exclude: [
      '**/multimedia/**',
      '/fonts/**',
      '/api/**',
      '**/search-api/**',
      '/group/*',
      '/router/**',
      '/route/**',
      '/node/**',
      '**/*.pdf',
      '**/*.doc',
      '**/*.docx',
      '**/*.rtf',
      '**/*.xls',
      '**/*.xlsx',
      '**/*.mp4',
      '**/*.avix',
    ],
  },
  ci: {
    // @ts-expect-error - This is a valid reporter
    reporter: 'csvExpanded',
  },
  hooks: {
    'resolved-config': function (config) {
      // Add byte weight column to report
      config.client.columns.performance.push({
        cols: 1,
        label: 'Byte Weight',
        tooltip: 'Total Byte Weight',
        sortKey: 'numericValue',
        key: 'report.audits.total-byte-weight',
      });

      // Reduce CLS column width to 1
      const clsColumn = config.client.columns.performance.find(
        (col) => col.key === 'report.audits.cumulative-layout-shift');
      if (clsColumn) {
        clsColumn.cols = 1;
      }
    },
    'task-complete': function (path, results) {
      if (results.report?.audits) {
        // CSV export excludes "informative" audits by default
        results.report.audits['total-byte-weight']['scoreDisplayMode'] = 'numeric';
        // Make byte weight clearer in web report.
        const byteWeight = results.report.audits['total-byte-weight'].numericValue;
        if (byteWeight) {
          results.report.audits['total-byte-weight']['displayValue'] = (byteWeight / 1024).toLocaleString(undefined, {
            maximumFractionDigits: 1,
            minimumFractionDigits: 1,
          }) + '  KiB';
        }
      }
    },
    'route-definitions-provided' : function (routes) {
      console.log(routes);
    }
  }
})

Has anyone any ideas as to what might be causing this?

Many thanks

Reproduction

Ran with command: npm run unlighthouse-ci --config-file /path/to/unlighthouse/unlighthouse.config.ts --debug

System / Nuxt Info

No response

@nmcltpx
Copy link
Author

nmcltpx commented Sep 19, 2024

I wonder if this is be a timeout from Lighthouse itself, not returning the score to unlighthouse.
If so, what can be done to mitigate it?

@nmcltpx
Copy link
Author

nmcltpx commented Sep 20, 2024

Is there any chance this fix can be rolled into a release? I am hitting this problem each time I run it.
Thanks

@harlan-zw
Copy link
Owner

Hi, sorry for the delay. Please try out the latest version 0.13.3 🙂

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

2 participants