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

Getting import error when using playAudit #50

Open
digracesion opened this issue Jul 3, 2023 · 4 comments
Open

Getting import error when using playAudit #50

digracesion opened this issue Jul 3, 2023 · 4 comments

Comments

@digracesion
Copy link

digracesion commented Jul 3, 2023

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

ahernd2 commented Aug 14, 2023

Seeing same issue

@edumserrano
Copy link

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.

@abhishekjha7798
Copy link

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?

@alphonse92
Copy link

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?

I posted my fix here without placing the "type" module

#72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants