playwright-lighthouse icon indicating copy to clipboard operation
playwright-lighthouse copied to clipboard

require() of ES Module playwright-lighthouse\index.js not supported.

Open szamacz opened this issue 1 year ago • 29 comments

After bumping the version from 2.2.2 to 31.1.0 Im getting an error flowing error in my project require() of ES Module playwright-lighthouse\index.js not supported. Playwright version - 1.35.1, lighthouse version - 10.3.0. I tried to set in package.json "type": "module", which removes the error but then playwright tests are not recognizable.

szamacz avatar Jul 03 '23 05:07 szamacz

getting this same issue as well. did you also end up with this issue after trying to downgrade the lighthouse version?

digracesion avatar Jul 03 '23 08:07 digracesion

Finally we have some solutions for this? I'm having the same issue. Any workaround?

RogerTarres avatar Jul 06 '23 15:07 RogerTarres

I'm just following the example on https://www.npmjs.com/package/playwright-lighthouse and I'm also having the same issue

MichaelRobsonSliide avatar Jul 10 '23 09:07 MichaelRobsonSliide

npm install --save-dev [email protected]

you can use this version which works until there is a fix for this problem

andreiancas22 avatar Jul 17 '23 07:07 andreiancas22

npm install --save-dev [email protected]

you can use this version which works until there is a fix for this problem

Doing this and I still get the error

petersenrr avatar Jul 20 '23 20:07 petersenrr

could anyone share a small repository where I can reproduce the same? Trying to resolve this by this week

abhinaba-ghosh avatar Jul 20 '23 20:07 abhinaba-ghosh

I believe this should help you in reproducing the issue. https://vinayksharma.medium.com/lighthouse-integration-with-playwright-d2b58386f77 The documents is learning material to integrate playwright with lighthouse and sample script has been provided as well.

sbettego avatar Jul 24 '23 06:07 sbettego

npm install --save-dev [email protected] you can use this version which works until there is a fix for this problem

Doing this and I still get the error

ahh ... for me it still works since i downgraded

andreiancas22 avatar Jul 24 '23 07:07 andreiancas22

@andreiancas22 , can you share the sample repo .

sbettego avatar Jul 25 '23 04:07 sbettego

this is the code that i am running:

import { test } from '@playwright/test';
import { playAudit } from 'playwright-lighthouse';
import playwright from 'playwright';
import lighthouseDesktopConfig from 'lighthouse/lighthouse-core/config/lr-desktop-config';

test.describe('audit example', () => {
    test('sample perf test', async () => {
        const url = 'https://app.creatopy.com/';

        const browser = await playwright['chromium'].launch({
            args: ['--remote-debugging-port=9222']
        });
        const page = await browser.newPage();
        await page.goto(url);
        await page.waitForLoadState('networkidle');
        await playAudit({
            page: page,
            config: lighthouseDesktopConfig,
            thresholds: {
                performance: 50,
                accessibility: 50,
                'best-practices': 50,
                seo: 50
            },
            port: 9222,
            reports: {
                formats: {
                    json: true,
                    html: true
                },
                name: 'audit'
            }
        });

        await browser.close();
    });
});

and this is the output that i got after running the test:

image

package.json content

image

andreiancas22 avatar Jul 25 '23 06:07 andreiancas22

thanks @andreiancas22 , it worked with the mentioned lighthouse & playwright-lightout version in your package.json along with the @playwright/test version that you are using. Since , we are using playwright 1.35.0 as of now and we might need to wait for the proper solution with latest playwright-lighthouse version.

sbettego avatar Jul 25 '23 08:07 sbettego

@sbettego glad that it helped, yea we need to wait for the playwright-lighthouse fix

andreiancas22 avatar Jul 25 '23 08:07 andreiancas22

So what should I do? Downgrading doesn't solve it for me.

petersenrr avatar Jul 25 '23 17:07 petersenrr

npm install --saveDev [email protected] [email protected] worked for me. Broken on 10.4.0 / 3.1.0 respectively.

mattfelten avatar Aug 03 '23 20:08 mattfelten

I'm also still encountering this issue even after downgrading to those versions

digracesion avatar Aug 04 '23 01:08 digracesion

Looking into this issue. Will update here once I have something

anshitbansal21 avatar Aug 07 '23 05:08 anshitbansal21

Adding "type": "module", to my package.json fixed this issue.

andrew-hossack avatar Aug 22 '23 15:08 andrew-hossack

Adding that to my package.json doesn't work. Is there any update on fixing this bug?

petersenrr avatar Sep 28 '23 16:09 petersenrr

Hello? Any update?

petersenrr avatar Oct 04 '23 17:10 petersenrr

yarn add -D [email protected] [email protected] worked for me 31.Oct.2023. If it get my test running I may be able look at the proper fix... any pointers would be appreciated.

ndp avatar Oct 31 '23 17:10 ndp

@andreiancas22 Did you face issues trying to use the page prop in the playAudit method?

ArCiGo avatar Nov 07 '23 13:11 ArCiGo

@andreiancas22 Did you face issues trying to use the page prop in the playAudit method?

no, it worked perfectly

andrei22b avatar Nov 07 '23 13:11 andrei22b

@andreiancas22 @andrei22b

I found the error (after doing more research and thanks to GitHub Copilot jajaja), and it was the incompatibility of the page value sent to the prop: playwright-lighthouse expects a Page object from playwright-core, not playwright.

Instead of using the default playwright import, I changed it to import { chromium, Page } from 'playwright-core', and it worked.

And, I downgraded the versions as suggested here: "lighthouse": "^9.6.8" and "playwright-lighthouse": "^2.2.2".

Thanks! :D

ArCiGo avatar Nov 08 '23 09:11 ArCiGo

Is there any update on this one? I've tried different combinations of package versions but still have the same error -

Error: require() of ES Module /node_modules/get-port/index.js from /workspaces/starter/next/playwright-tests/utils/index.ts not supported.
Instead change the require of index.js in /playwright-tests/utils/index.ts to a dynamic import() which is available in all CommonJS modules.

rjgux avatar Feb 15 '24 16:02 rjgux