Open bachhavdipak opened 4 months ago
I am using the @playwright/test package as well with playwright-lighthouse and getting the same type of error:
Error: require() of ES Module <repo path>/node_modules/playwright-lighthouse/index.js from <repo path>/packages/integration-tests/src/tests/audit.spec.ts not supported.
Instead change the require of index.js in <repo path>/packages/integration-tests/src/tests/pharmacy/audit.spec.ts to a dynamic import() which is available in all CommonJS modules
I am importing the playwright-lighthouse package like this: import { playAudit } from 'playwright-lighthouse';
And this is my tsconfig.json file:
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"esModuleInterop": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"baseUrl": "./src",
"noEmit": true,
"strict": false,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"paths": {
"~/*": ["*"],
}
},
"include": ["src"]
}
As suggested on the stackoverflow link provided on https://github.com/abhinaba-ghosh/playwright-lighthouse/issues/45, adding:
"type": "module",
to my package.json solved the issue.
What if someone does not want to add "type": "module" in their package.json because project is configured with commonjs? How can we use playwright-lighthouse if package type is not a module?
0
I am trying to use lighthouse with my playwright cucumber project but getting below error::
.F--.
Failures:
1) Scenario: Evaluate the performance of the homepage # src\test\features\ecomm\lighthouse.feature:4 √ Before # src\hooks\hooks.ts:19 × Given I am on the homepage # src\test\steps\ecomm\lighthouse.ts:34 Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Playwright\node_modules\playwright-lighthouse\index.js from C:\Playwright\src\pages\example\exampleHomePage.ts not supported. Instead change the require of index.js in C:\Playwright\src\pages\example\exampleHomePage.ts to a dynamic import() which is available in all CommonJS modules. at require.extensions. [as .js] (C:Playwright\node_modules\ts-node\dist\index.js:851:20)
at C:Playwright\src\pages\example\exampleHomePage.ts:132:94
StepDef file :
ExampleHomePage: