Fix ERR_REQUIRE_ESM: Use dynamic import for uuid

This commit is contained in:
2025-12-27 23:13:47 +11:00
parent 782aaf63a6
commit f7a1f1be42

View File

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