Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "ighthouseLib is not a function" after upgrade lighthouse package to version 12.x #239

Open
mjalav opened this issue Oct 8, 2024 · 0 comments

Comments

@mjalav
Copy link

mjalav commented Oct 8, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @cypress-audit/[email protected] for the project I'm working on.

I got an error when I upgraded lighthouse to version 12.x and the error was "lighthouseLib is not a function"
Here is the diff that solved my problem:

diff --git a/node_modules/@cypress-audit/lighthouse/src/task.js b/node_modules/@cypress-audit/lighthouse/src/task.js
index 72a6526..5553930 100644
--- a/node_modules/@cypress-audit/lighthouse/src/task.js
+++ b/node_modules/@cypress-audit/lighthouse/src/task.js
@@ -1,13 +1,8 @@
-const lighthouseLib = require("lighthouse/core/index.cjs").legacyNavigation;
-const {
-  computeCategories,
-  computeAudits,
-  compareWithThresholds,
-} = require("./helpers");
+const { computeCategories, computeAudits, compareWithThresholds } = require('./helpers');
 
 const lighthouse =
   (callback) =>
-  ({ url, thresholds, opts = {}, config }) => {
+    async ({ url, thresholds, opts = {}, config }) => {
     if (global.cypress_audit_port) {
       opts.port = global.cypress_audit_port;
 
@@ -19,10 +14,13 @@ const lighthouse =
         opts.disableStorageReset = true;
       }
 
-      return lighthouseLib(url, opts, config).then((results) => {
-        if (callback) {
-          callback(results);
-        }
+  // Use dynamic import for 'lighthouse'
+  const lighthouse = (await import('lighthouse')).default;
+
+  return lighthouse(url, opts, config).then((results) => {
+    if (callback) {
+      callback(results);
+    }
 
         const computedAudits = computeAudits(results.lhr.audits);
         const computedCategories = computeCategories(results.lhr.categories);

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant