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

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

Open
szamacz opened this issue Jul 3, 2023 · 29 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@szamacz
Copy link

szamacz commented Jul 3, 2023

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
Copy link

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

@RogerTarres
Copy link

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

@MichaelRobsonSliide
Copy link

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

@andreiancas22
Copy link

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
Copy link

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
Copy link
Owner

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

@sbettego
Copy link

sbettego commented Jul 24, 2023

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
Copy link

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
Copy link

@andreiancas22 , can you share the sample repo .

@andreiancas22
Copy link

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
Copy link

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
Copy link

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

@petersenrr
Copy link

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

@mattfelten
Copy link

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
Copy link

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

@abhinaba-ghosh abhinaba-ghosh added the bug Something isn't working label Aug 5, 2023
@anshitbansal21
Copy link

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

@andrew-hossack
Copy link

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

@petersenrr
Copy link

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

@petersenrr
Copy link

Hello? Any update?

@ndp
Copy link

ndp commented Oct 31, 2023

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
Copy link

ArCiGo commented Nov 7, 2023

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

@andrei22b
Copy link

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

no, it worked perfectly

@ArCiGo
Copy link

ArCiGo commented Nov 8, 2023

@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
Copy link

rjgux commented Feb 15, 2024

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
Copy link

any updates?

@stijnelskens
Copy link

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

@tompeace
Copy link

tompeace commented Jul 18, 2024

@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
Copy link

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
Copy link

I posted the solution here: #72 if some of you are looking for info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests