Recently, I tried to upgrade my old React app to use Vite instead of Create React App, because CRA has been deprecated. However, I noticed my embedded Observable chart with Runtime no longer works.
I am using the same embed code, but I get the error saying “Unexpected token ‘<’, "<!DOCTYPE "… is not valid JSON.” The current instructions for embedding Observable charts still use CRA. Does anyone know how I can update the embed code to support Vite + React projects?
I suspect that Vite fails to be bundle the file attachments, and that the Runtime error that you see is a 404 response when the notebook tries to fetch the geojson file. You may want to check if the attachments are present in the built files.
You should be able to view the full response by selecting the request in your devtools network tab and then selecting the preview tab.
However, the “deps” folder doesn’t have any subfolders after I run “npm install”. Simply placing the data files in the “public” folder doesn’t address this issue.
Did you mean to write “404”? Although I’d be surprised if you saw an error at all, because afaict Vite simply serves the entry page (hence the <!doctype ...).
It’s not even needed for the build, where according to my tests the file attachments get included and referenced correctly. So the problem is limited to the dev server / HMR because for some reason Vite doesn’t handle the asset path there.
Edit: I can observe the exact same problem in a vanilla JS setup.
I’d consider this a bug in Vite and file an issue in their repo. Try to keep your reproduction example simple, and ideally leave React out of it since it’s not required to reproduce the problem.