✅ Solved: Trouble Using Rive ViewModels with Basic JavaScript (No Bundler)
I'm working on a small Rive project to test out data binding with ViewModels in a simple HTML and JavaScript setup. No bundler, just basic browser development. I'm running into a lot of issues, and I'm wondering if this approach is even supported or possible without switching to something like Vite or Electron.
So far, I’ve been able to use JavaScript to control Rive’s State Machine inputs without any problem. I can trigger animations, set numeric values, and interact with the file as long as I stick to inputs. That part works great.
The problems begin when I try to use ViewModels for data binding. I’ve added a ViewModel inside my .riv file and tried to have the JS communicate with it. The Rive file itself seems to be set up correctly, but I can't get JavaScript to interact with the ViewModel properties at runtime without having Chrome console errors and it not loading.
Here are the issues I’ve encountered:
Trying to use import statements to load @rive-app/canvas-advanced causes syntax errors like “Cannot use import statement outside a module.”
Trying to access the viewModel object returns undefined or throws errors.
I get CORS errors when attempting to load rive.wasm from a CDN.
The browser doesn’t recognize the Rive runtime when using the advanced features.
Even if the .riv file loads, defaultArtboard or viewModel access fails, likely because the advanced runtime isn’t properly loaded.
What I’ve gathered from talking with ChatGPT is that ViewModels only work with @rive-app/canvas-advanced, and that package only works in environments that support ES modules and bundling — such as Vite, Webpack, or Electron.
So my question is:
Is there any way to use Rive ViewModels and data binding in a simple HTML + JavaScript setup without a build system or bundler? Or is using something like Vite or Electron the only way to make that work? I understand basic JS/HTML, but ChatGPT is insisting that more advanced developer “bundles” (Vite etc) are needed, which are outside of my understanding. It is hard to find info on this and maybe ChatGPT is hallucinating and leading me on a wild goose chase.
Thanks for any help or clarification!
———————
ATTACHMENTS:
Here are the two simple project folders (zipped)
https://drive.google.com/drive/folders/1zk7dk_DwuhaEq_SL5392cYxR4gFYUrIt?usp=sharing
The projects are simple. Each is just a javascript with a hardcoded number, which should fill a green progress bar. It is set to “7” which fills it 70%.
It totally works on the "state machine" version.
However it has Chrome console errors on the "databinding" version. I tried to create it the same way, but just changing it from state machine inputs to ViewModel values. Both projects include the .rev backup files as well.
You can open terminal and "cd" into a folder, then write python3 -m http.server
Then you can visit the URL http://localhost:8000/ to see the Rive file.