-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Multiline Vue component props breaks import.meta.env #5387
Multiline Vue component props breaks import.meta.env #5387
Comments
I ran into the same issue ( |
I should mention I have solved this by exporting all needed env values from a separate file: // fx utils/env.ts
export const MODE = import.meta.env.MODE
export const PROD = import.meta.env.PROD This allows for easy mocking as well during tests. |
It looks like When I locally debug the code around here: vitest/packages/vitest/src/node/plugins/ssrReplacer.ts Lines 16 to 18 in 6eda473
I see following transformations: Hello.vue
<template>
<SomeOtherComponent
:some-prop="
testValue
? 'A long value to break handling of env variables'
: 'it needs to break into a new line'
"
>
...
</SomeOtherComponent>
</template>
<script lang="ts">
...
console.log(import.meta.env.MODE);
<template>
<SomeOtherComponent
:some-prop=""
testValue
? ' '
: ' '
""
>
...
</SomeOtherComponent>
</template>
<script lang=" ">
...
console.log(import.meta.env.MODE);
<template>
<SomeOtherComponent
:some-prop="
testValue
? 'A long value to break handling of env variables'
: 'it needs to break into a new line'
"
>
...
</SomeOtherComponent>
</template>
<script lang="ts">
...
console.log(im__vite_ssr_import_meta__.envODE); |
This is fixed in strip-literal v2.1.0. You can upgrade the transitive dependency either by re-creating lockfile or tools such as I confirmed the reproduction is fixed using package.json |
- fixes vitest-dev/vitest#5387 (comment) Signed-off-by: Peter Makowski <[email protected]>
- fixes vitest-dev/vitest#5387 (comment) Signed-off-by: Peter Makowski <[email protected]>
- fixes vitest-dev/vitest#5387 (comment) Signed-off-by: Peter Makowski <[email protected]>
- update strip-literal to 2.1.0 - fixes vitest-dev/vitest#5387 (comment) - add rerender with state updates in renderWithMockStore using immer `produce`. - add `immer` as a dev dependency
Describe the bug
When passing a component property which folds into multiple lines, any use of
import.meta.env
breaks the test and shows the following error:ReferenceError: im__vite_ssr_import_meta__ is not defined
Using the following example, the error occurs when the ternary condition inside
some-prop
folds into multiple lines. If the text was shortened to fx.:some-prop="testValue ? 'Hello' : 'World'"
the error does not occur. This also happens when passing object-syntax to class attributes etc.The error does not occur in Vitest < 1.3.0.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-tfewql?file=components%2FHello.vue
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: