mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-18 04:05:58 +00:00
Fix ERR_REQUIRE_ESM: Use dynamic import for Lighthouse
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const lighthouse = require('lighthouse');
|
// lighthouse is ESM only, imported dynamically
|
||||||
const chromeLauncher = require('chrome-launcher');
|
const chromeLauncher = require('chrome-launcher');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@@ -11,6 +11,9 @@ const { v4: uuidv4 } = require('uuid');
|
|||||||
* @returns {Promise<object>} - Test results
|
* @returns {Promise<object>} - Test results
|
||||||
*/
|
*/
|
||||||
async function runTest(url, options = {}) {
|
async function runTest(url, options = {}) {
|
||||||
|
// Dynamically import Lighthouse (ESM)
|
||||||
|
const { default: lighthouse } = await import('lighthouse');
|
||||||
|
|
||||||
const isMobile = options.isMobile ?? true; // Default to mobile
|
const isMobile = options.isMobile ?? true; // Default to mobile
|
||||||
const reportDir = path.join(__dirname, '..', 'reports');
|
const reportDir = path.join(__dirname, '..', 'reports');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user