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
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 clientOr use a resource for the await import(...) with the option for an initialValue.
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