Fix ERR_REQUIRE_ESM: Use dynamic import for Lighthouse

This commit is contained in:
2025-12-27 23:03:51 +11:00
parent debc643780
commit 557cb3261f

View File

@@ -1,4 +1,4 @@
const lighthouse = require('lighthouse');
// lighthouse is ESM only, imported dynamically
const chromeLauncher = require('chrome-launcher');
const fs = require('fs');
const path = require('path');
@@ -11,6 +11,9 @@ const { v4: uuidv4 } = require('uuid');
* @returns {Promise<object>} - Test results
*/
async function runTest(url, options = {}) {
// Dynamically import Lighthouse (ESM)
const { default: lighthouse } = await import('lighthouse');
const isMobile = options.isMobile ?? true; // Default to mobile
const reportDir = path.join(__dirname, '..', 'reports');