playwright-lighthouse icon indicating copy to clipboard operation
playwright-lighthouse copied to clipboard

Getting import error when using playAudit

Open digracesion opened this issue 1 year ago • 4 comments

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.

digracesion avatar Jul 03 '23 01:07 digracesion

Seeing same issue

ahernd2 avatar Aug 14 '23 10:08 ahernd2

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.

edumserrano avatar Dec 30 '23 19:12 edumserrano

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?

abhishekjha7798 avatar Mar 16 '24 19:03 abhishekjha7798