-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
When running Vitest on a project using Vite 6 and Vike (>=0.4.221), Vitest throws an error:
Error: [module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.PUBLIC_ENV__FOO" instead.
This error occurs when Vitest processes a file (in my case, a Vike config file like +bodyHtmlBegin.ts
) that contains static access to an environment variable, like:
export const bodyHtmlBegin = import.meta.env.PUBLIC_ENV__FOO;
While the trigger involves Vike, the inaccurate error message might be an issue on Vitest side.
Additional Context:
This issue was initially reported and discussed in the Vike project here: vikejs/vike#2412
cc @brillout
Reproduction
- Clone the repo:
git clone git@github.com:alexmnv/vike-env-issue-test.git
cd vike-env-issue-test
npm install
- Run Vitest:
npm run test
Expected Behavior:
Vitest should not throw a "Dynamic access" error when the code uses static access (import.meta.env.VAR
).
Actual Behavior:
Vitest throws the following misleading error:
Error: [module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.PUBLIC_ENV__FOO" instead.
System Info
System:
OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (16) x64 AMD Ryzen 7 5800U with Radeon Graphics
Memory: 6.54 GB / 30.67 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.3.0 - ~/.nvm/versions/node/v22.3.0/bin/node
npm: 10.8.1 - ~/.nvm/versions/node/v22.3.0/bin/npm
Browsers:
Chrome: 135.0.7049.95
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
brillout
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)