Subscribe on changes!

OnMount ref in Script setup ref undefined when OnMount ref in setup are

avatar
Oct 14th 2021

Version

3.2.20

Reproduction link

codesandbox.io

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

avatar
Oct 14th 2021

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

avatar
Oct 14th 2021

@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

avatar
Oct 14th 2021

@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 .

avatar
Oct 14th 2021

@LinusBorg i finally found the issue if i upgrade to "@vitejs/plugin-vue": "^1.9.3" and "vite": "^2.6.7" it works

avatar
Oct 14th 2021

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.

avatar
Oct 14th 2021

@LinusBorg i did removed the 3.0.0-0 and it's still doesn't in code sandbox.

avatar
Oct 14th 2021

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.

avatar
Oct 14th 2021

Thanks for the help, it work on my side now.