Fix ERR_REQUIRE_ESM: Use dynamic import for Chrome Launcher

This commit is contained in:
2025-12-27 23:10:02 +11:00
parent 557cb3261f
commit 782aaf63a6

View File

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