Rayrun
← Back to Discord Forum

SyntaxError: Cannot use 'import.meta' outside a module

I have a pnpm monorepo. One of the packages which is not a vite app and is using import.meta.env but is used exclusively by vite (see vite env variables: https://vitejs.dev/guide/env-and-mode.html#env-variables). This works for our apps, because all of them importing the package including import.meta.env. Though, when I start a playwright test it complains.

How can I fix this?

This thread is trying to answer question "How can I fix the 'SyntaxError: Cannot use 'import.meta' outside a module' error when starting a playwright test in a pnpm monorepo?"

4 replies

One thing that worked for me, but only consider a workaround ist using process.env instead and defining those variables in the vite.config.ts. But I would prefer a way that works with import.meta directly

nikomel9796

I'm having the same issue now. @lukaskllr were you able to resolve it?

@nikomel9796: Unfortunately not. IIRC I used some workaround to make it work

Unfortunately not. IIRC I used some workaround to make it work

nikomel9796

Could you please share details of this workaround, if you may?

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].