OnMount ref in Script setup ref undefined when OnMount ref in setup are
Version
3.2.20
Reproduction link
Steps to reproduce
Error one => https://codesandbox.io/s/unruffled-snow-3u1ol?file=/src/components/Slider.vue Working one => https://codesandbox.io/s/cold-brook-8cr41?file=/src/components/Slider.vue
What is expected?
Both should work in the same way
What is actually happening?
The ref in OnMount in script setup is undefined
if you change @vue/compiler-sfc
to version "3.2.20" in package.json it works. the codesandbox seems to use an older version.
It also works in the playground
@LinusBorg i removed @vue/compiler-sfc
in codesandbox, as it's said there : https://www.npmjs.com/package/@vue/compiler-sfc
Note: as of 3.2.13+, this package is included as a dependency of the main vue package and can be accessed as vue/compiler-sfc. This means you no longer need to explicitly install this package and ensure its version match that of vue's. Just use the main vue/compiler-sfc deep import instead.
it's include in vue now right.
It should work so.
Edit: i did add @vue/compiler-sfc
to try, and it's doesn't work too :
https://codesandbox.io/s/unruffled-snow-3u1ol?file=/src/components/Slider.vue
@LinusBorg it's not really kind to close issue straight away, like that. I see in your playground it work, cool. But not in my project and not in codesandbox, event if i add a package who said you don't need to include it anymore .... Make a codesandbox work and then you can close it .
@LinusBorg i finally found the issue if i upgrade to "@vitejs/plugin-vue": "^1.9.3" and "vite": "^2.6.7" it works
And it worked in your codesandbox when I sued the appropriate compiler version in dependencies, that's why I closed it. You had it in dependencies, but with version "3.0.0-0"
.
I don't know what's up with the current state of the sandbox though.
It works in a fresh Vue CLI (just tried myself) and a fresh Vite project (as per your own comment). I won't try and debug that codeandbox to get it working again.