abhinaba-ghosh / playwright-lighthouse

:performing_arts:: Playwright Lighthouse Audit
https://www.npmjs.com/package/playwright-lighthouse
MIT License
240 stars 28 forks source link

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

Open szamacz opened 1 year ago

szamacz commented 1 year ago

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.

digracesion commented 1 year ago

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

RogerTarres commented 1 year ago

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

MichaelRobsonSliide commented 1 year ago

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

andreiancas22 commented 1 year ago

npm install --save-dev playwright-lighthouse@2.2.2

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

petersenrr commented 1 year ago

npm install --save-dev playwright-lighthouse@2.2.2

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

Doing this and I still get the error

abhinaba-ghosh commented 1 year ago

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

sbettego commented 1 year ago

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.

andreiancas22 commented 1 year ago

npm install --save-dev playwright-lighthouse@2.2.2 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

sbettego commented 1 year ago

@andreiancas22 , can you share the sample repo .

andreiancas22 commented 1 year ago

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

sbettego commented 1 year ago

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.

andreiancas22 commented 1 year ago

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

petersenrr commented 1 year ago

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

mattfelten commented 1 year ago

npm install --saveDev lighthouse@9.6.8 playwright-lighthouse@2.2.2 worked for me. Broken on 10.4.0 / 3.1.0 respectively.

digracesion commented 1 year ago

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

anshitbansal21 commented 1 year ago

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

andrew-hossack commented 1 year ago

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

petersenrr commented 1 year ago

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

petersenrr commented 1 year ago

Hello? Any update?

ndp commented 11 months ago

yarn add -D lighthouse@9.6.8 playwright-lighthouse@2.2.2 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.

ArCiGo commented 11 months ago

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

andrei22b commented 11 months ago

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

no, it worked perfectly

ArCiGo commented 11 months ago

@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

rjgux commented 7 months ago

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.
withinoneyear commented 4 months ago

any updates?

stijnelskens commented 2 months ago

Encountering the same problem here.. Just wondering what the status is

tompeace commented 2 months ago

@stijnelskens adding "type": "module" to the package.json helped for me. I used npx playwright init to bootstrap the test suite for my app (which lives in another folder and has a separate package.json) so this worked fine but if you are integrating playwright into something already existing it might not work for you.

alphonse92 commented 2 months ago

the module lighthouse/report/generator/report-generator is now a ESmodule that make it incompatible with the current module system that is "commonJS" so, you need to import it via "import("lighthouse/report/generator/report-generator")"

alphonse92 commented 1 month ago

I posted the solution here: https://github.com/abhinaba-ghosh/playwright-lighthouse/issues/72 if some of you are looking for info