#Adding TomSelect to vite

7 messages · Page 1 of 1 (latest)

tacit willow
#

I'm trying to add TomSelect : https://tom-select.js.org/ to a new Laravel project using Vite package manager.

So in app.js I have:

import TomSelect from 'tom-select';

window.TomSelect = TomSelect;

but when I try to initialize the plugin in my blade:

<script>
    new TomSelect('#authors');
</script>

i get error: "Uncaught ReferenceError: TomSelect is not defined"

Has anyone managed to add it and tell me what I'm doing wrong?

livid canyon
#

The issue is most likely due to the vite script being deferred while your inline isn't

#

But that's just a guess without testing it myself

tacit willow
#

This can be it - in the console it first throws the error, and then displays "[vite] connecting..."

livid canyon
#

You can tinker with it, but that's my guess

#

At work, so can't confirm myself

tacit willow
#

Thanks! At least I have some direction to research now