HTML Report generation: Cannot read property 'channel' of undefined
See original GitHub issueSteps to reproduce
I used the following code to get statistics for a webpage using LH and Puppeteer. Issue can be reproduced for different pages, provided example is for http://www.google.com
- Create a function to get a report (typescript):
import * as path from 'path';
import * as fs from 'fs';
import lighthouse from 'lighthouse';
import ReportGenerator from 'lighthouse/lighthouse-core/report/report-generator';
import { Page } from 'puppeteer';
import { Generic } from '../Generic'; // It contains only custom logging function, can be commented
import perfConfig from './perf-config'; // LH performance config file from sample configs
export class UIPerformance {
public static async getLighthouseMetrics(page: Page, filename: string) {
const port = await page.browser().wsEndpoint().split(':')[2].split('/')[0];
try {
let results: any;
results = await lighthouse(page.url(), { port: port }, perfConfig);
const jsonReport = ReportGenerator.generateReport(results.lhr, 'json');
const htmlReport = ReportGenerator.generateReport(results.report, 'html');
delete results.artifacts;
const rootDir = path.normalize(path.join(__dirname, '../../'));
const lighthouseReportsPath = path.join(rootDir, 'lighthouseReports');
fs.mkdirSync(lighthouseReportsPath, { recursive: true });
fs.writeFile(`${lighthouseReportsPath}/${filename}.json`, jsonReport, (err) => {
if (err) {
Generic.logToConsole(err);
};
Generic.logToConsole(`Lighthouse JSON report saved to ${lighthouseReportsPath}/${filename}.json`);
});
fs.writeFile(`${lighthouseReportsPath}/${filename}.html`, htmlReport, (err) => {
if (err) {
Generic.logToConsole(err);
};
Generic.logToConsole(`Lighthouse HTML report saved to ${lighthouseReportsPath}/${filename}.html`);
});
} catch (err) {
Generic.logToConsole(err);
}
}
}
- Launch puppeteer, open browser, page, go to url.
- Call the function. I run this function in my mocha tests.
What is the current behavior?
Two reports were generated (JSON and HTML). Chrome is not able to display html file properly. It shows just blank page and throws an error in a console:
compiled-reportrenderer.js:3783 Uncaught TypeError: Cannot read property 'channel' of undefined
at ReportRenderer.renderReport (compiled-reportrenderer.js:3783)
at __initLighthouseReport__ (MainPage.html:6480)
Both reports are attached. lighthouseReports.zip
What is the expected behavior?
Two reports should be generated (JSON and HTML). HTML file should be opened properly in Chrome.
Environment Information
- Affected Channels: CLI, ReportRenderer
- Lighthouse version: 5.2.0
- Node.js version: 3.5.2
- Operating System: Windows 10
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
i getting error Cannot read property 'channels' of undefined
As you define guild one line above, it means client.guilds.cache.get('787083837833871400') returns undefined. Make sure the guild ID is correct.
Read more >cannot read properties of undefined (reading 'permissions')
Try using optional chaining for your assignment to voiceChannel. Something like const voiceChannel = message?.member?.voice?.channel;. In cases where there is ...
Read more >Process | Node.js v19.3.0 Documentation
If the Node.js process is spawned with an IPC channel (see the Child Process ... The process.argv0 property stores a read-only copy of...
Read more >Error message : "Unable to get property 'rows' of undefined or ...
Error message : "Unable to get property 'rows' of undefined or null on the reference” received on the scheduled Report Designer reports.
Read more >Visual Studio Feedback
Your open channel to Microsoft engineering teams. Select a page ... TypeError: Cannot read property 'updateStartupCommandAndRuntimeStack' of undefined.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fs.writeFileSync('myfile.json', JSON.stringify(results.lhr))
is what you are looking for to avoid the[object Object]
, this is exactly whatReportGenerator.generateReport
does@connorjclark thanks a lot.
works fine for html, but it generates json file with the following content:
[object Object]
Is it correct?As a workaround I did the following: