using vanilla js with import?

I am playing around with ways to visualize data and I would like to be able to use vanilla js to do so. I understand that I could do things with onmount and other solid provided techniques but I thought it would be cool to try to import a js file. It did work, but it seems to have been "minified" or whatever happens when your code is built for production. The image provided is actually a whole javascript file that seems to have been stuck inside of index-05a...js , and it works as intended until you try to do anything that interacts with the dom, at which point it errors and says document is undefined. So, is there an easy workaround to be able to use my js file in solid or should I stick to using solid as intended? Thank you
3 Replies
thetarnav
thetarnav2y ago
Document being undefined is because of SSR, right? In which case it doesn’t matter if you “use solid” or “use vanilla js”, you cannot touch DOM apis on the server Try importing it dynamically in onMount so it’s loaded only on the client
Alex Lohr
Alex Lohr2y ago
Or use a resource for the await import(...) with the option for an initialValue.
romanobro
romanobroOP2y ago
Awesome! after poking around (and searching how to dynamically import lol) I can now use vanilla js files alongside solid. although I am getting "is not a module" error, but it works. Thank you both
Want results from more Discord servers?
Add your server