playwright-lighthouse
playwright-lighthouse copied to clipboard
Getting import error when using playAudit
Everytime I run my tests, I'm encountering the following error message:
SyntaxError: Unexpected token 'export'
1 | import { test, chromium } from '@playwright/test';
> 2 | import { playAudit } from 'playwright-lighthouse';
| ^
3 | import lighthouse from 'lighthouse';
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (resources/js/tests/e2e/audit.spec.ts:2:1)
But package.json
shows playwright-lighthouse": "^3.1.0
, so I'm quite confused as to what's wrong here.
I tried installing npm i -D tsconfig-paths
thinking that maybe this was an issue with the reading from the ts file and I'm currently seeing the following:
Error: require() of ES Module /Users/gray/yaraku/zen/node_modules/playwright-lighthouse/index.js from /Users/gray/yaraku/zen/resources/js/tests/e2e/audit.spec.ts not supported.
Instead change the require of index.js in /Users/gray/yaraku/zen/resources/js/tests/e2e/audit.spec.ts to a dynamic import() which is available in all CommonJS modules.
Seeing same issue
I'm also getting this, seems like a duplicate of #45.
As suggested on the stackoverflow link provided on #45, adding:
"type": "module",
to my package.json
solved the issue.
There's also this question at #46 but there's no response so I'm not sure if there's an alternative to the solution above.
What if someone does not want to add "type": "module" in their package.json because project is configured with commonjs? Do we have any other solution?