I’m using the code snippets to embed my notebook in react. However, when I run ‘yarn start’ I get a ‘failed to compile error’ complaining about the fileattachments.
I did follow these instructions, also provided in embed window but it did not seem to solve the issue. For file attachments to work with Babel, add @babel/plugin-syntax-import-meta to the 'plugins' section of your Babel config
I also followed the hack given here: how do i embed the notebook in react, where I replaced ‘new URL("./files…’ with ‘require("./files…’ which has worked for me before, however I’m still getting this error:
I was hoping the instructions in the embed window about file attachments working with babel would have fixed this. Is this work around still necessary or is there a fix?
you could also use their react example using rollup to bundle it
This Rollup configuration supports file attachments, whereas many React environments (like the one you get from create-react-app ) stumble on file attachments’ use of import.meta.
Ah, so I see when I download the code there is no json file and in the above repo I don’t see where he has put the flare.json file, so not sure how it is supposed to work… I could download manually, but if I follow the instructions in this how to embed notebook, the json file does copy over… strange.
Oh weird, yes if I download using the Download Code button and use unarchiver to unzip the files do not show. If I use yarn add then the files are downlaoded but with no extension.
If I change the extension to .json and the update the code to const fileAttachments = new Map([["flare-2.json",require("./files/e65374209781891f37dea1e7a6e1c5e020a3009b8aedf113b4c80942018887a1176ad4945cf14444603ff91d3da371b3b0d72419fa8d2ee0f6e815732475d5de.json")]])
I still see a
RuntimeError: Unexpected token < in JSON at position 0
but good grief that seems complicated (manually moving so many files around).
The require work around you mentioned in a previous post @radames no longer seems to work for me. Too bad, it was less work as I didn’t have to move the json files to public.
Thanks for letting me know it’s still possible with require. Yeah, the whole ‘bundler’ thing is foreign to me. I would like to automate these steps so every time I want to download an updated version of the notebook it’s easy.