Skip to content
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

Imported constants produce undefined when inside template string in DEV mode #4340

Closed
sheremet-va opened this issue Aug 15, 2021 · 7 comments
Labels
has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working scope: sfc

Comments

@sheremet-va
Copy link

sheremet-va commented Aug 15, 2021

Version

3.2.2

Reproduction link

https://codesandbox.io/s/musing-lake-jx008?file=/src/App.vue

Steps to reproduce

Create test.ts file:

export const VARIABLE = '123';

Create Comp.vue file:

<script setup lang="ts">
import { VARIABLE } from './test'
</script>

<template>
    <div>{{ `${VARIABLE}123` }}</div>
</template>

What is expected?

123123 on screen

What is actually happening?

undefined123 on screen

@HcySunYang
Copy link
Member

Update the dependency package (vue/vue-cli) to the latest version will not have this issue.

@sheremet-va
Copy link
Author

sheremet-va commented Aug 15, 2021

I don't use vue-cli, I am using Vite. Repro link inside the issue was provided by your creating issues template. I just reproduced the error.

The problem was a non-issue, until I updated my dependencies to the latest versions. I have my versions strict. (without ^). And only ^3.2.0 gives me this unexpected behavior.

@sheremet-va
Copy link
Author

And the latest vue release is 3.2.2

@sheremet-va
Copy link
Author

sheremet-va commented Aug 15, 2021

Снимок экрана 2021-08-15 в 11 29 16

Here, I made a reproduction (using Vite starter template): https://github.com/sheremet-va/vue-template-string-setup-bug

@HcySunYang HcySunYang reopened this Aug 15, 2021
@HcySunYang
Copy link
Member

HcySunYang commented Aug 15, 2021

As a workaround, change this:

<div>{{ `${VARIABLE}123` }}</div>

to

<div>{{ VARIABLE }}123</div>
<!-- or -->
<div>{{ VARIABLE + `123` }}</div>

@HcySunYang HcySunYang added 🐞 bug Something isn't working scope: sfc has workaround A workaround has been found to avoid the problem labels Aug 15, 2021
@sheremet-va
Copy link
Author

I want to point out, that the problem persist not only inside {{ }}, but inside any template string ('`'). For example, inside :name="`${VARIABLE}123`"

But workaround is working, yes.

@HcySunYang
Copy link
Member

Just add a hint here, we can't completely strip the Template strings(Template literals), https://github.com/vuejs/vue-next/blob/master/packages/compiler-sfc/src/compileScript.ts#L2249

@github-actions github-actions bot locked and limited conversation to collaborators Oct 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working scope: sfc
Projects
None yet
Development

No branches or pull requests

3 participants
@HcySunYang @sheremet-va and others