Ask Your Question

Revision history [back]

The error message "Error [ERRREQUIREESM]: require()" indicates that there is a problem with how the code is importing a module in Playwright Lighthouse with TypeScript (TS). This error message occurs when the imported module is not an ECMAScript Module (ESM) but the code is trying to treat it as one using the import statement. It happens because the code is attempting to import a CommonJS module using the ESM syntax.

To fix this error, you need to ensure that the module you're importing is compatible with TypeScript and ESM. One solution is to use a bridging module that exports and imports the required functions and methods, as Playwright also supports CommonJS. Another solution is to use a polyfill that enables the compatibility between CommonJS and ESM. Alternatively, you can update your package.json to use "type": "module" and "exports" fields.