loadEnv inside of workspace #5003
Unanswered
JamesGreenaway
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Thanks for the report. It sounds like a bug. I would appreciate if you can provide a minimal reproduction so that it's easier to investigate for maintainers. |
Beta Was this translation helpful? Give feedback.
0 replies
-
To make sure we're looking at the same issue, could you confirm https://stackblitz.com/edit/github-2srz39?file=packages%2Flib1%2Fvite.config.ts $ npx vitest run
FAIL |lib1| test/double.test.ts > env
AssertionError: expected undefined to be 'hello' // Object.is equality
- Expected:
"hello"
+ Received:
undefined
❯ eval test/double.test.ts:8:35
6|
7| test('env', () => {
8| expect(process.env['SOME_ENV']).toBe('hello');
| ^
9| });
10|
$ npx vitest run --root packages/lib1
...
✓ test/double.test.ts (2)
✓ double
✓ env |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to load all the environment variables inside a project without a VITE prefix.
I can do this at a project level by adding:
This loads my
.env
file as expected i.e. all the variables including all those that are not prefixed by VITE.However, when I run Vitest from the root of the monorepo it doesn't load the env vars - they return as
undefined
. Nothing happens either, if I add theloadEnv
function to my workspace config as anenv
property and extend the path to the correct location like so:env: loadEnv("", `${process.cwd()}/apps/my-app`, "")
How can I have un-prefixed environment variables inside a workspace config on a per-project basis?
I am able to get the expected result, if I add a
vitest.config.ts
at the root like so:Unfortunately this prevents me from loading any more than a single app's environment variables as it is not project specific. I can't seem rename the file and add it to the workspace config manually either, it must be
vitest.config.ts
or the workspace config will not see it?!Beta Was this translation helpful? Give feedback.
All reactions