I’m encountering an issue with environment variable access in my tests for a project using Vite as a build tool alongside a React app. In the React app, environment variables are accessed via import.meta.env
, but in our tests, we rely on process.env
and .env
files using the dotenv
package.
I’m seeing the following error:
TypeError: Cannot read properties of undefined (reading ‘ENV_VAR’)
Could anyone suggest how to resolve this issue and properly access ENV_VAR within both the React app and the test environment?
Link to the repo with repro example: https://github.com/omelnik/playwright-vite-repro