I have built a minimal template of a Gatsby blog/website that allows you to author posts in Observable. It’s taken me quite a while to make it work, so I thought it may be useful to others.
You can find the site readme/code here and you can see the notebooks in action here e.g. here
Thanks for the great examples! I’m trying to follow your setup and use a similar workflow (observable + gatsbyjs + github pages) but I can’t seem to import my notebook into Gabsy after yarn install-ing.
import {Runtime, Inspector} from "@observablehq/runtime";
import define from "@horatiubota/romanias-population-from-1992-to-2017";
but the import kept failing with an Unexpected token 6:217 error which wasn’t very helpful. So I created a simple react app with npx create-react-app test-app just to check if I can import the notebook in react directly, but that also fails with:
SyntaxError: /node_modules/@horatiubota/romanias-population-from-1992-to-2017/b98216c7af6b40c2@220.js:
Support for the experimental syntax 'importMeta' isn't currently enabled (6:219).
Add @babel/plugin-syntax-import-meta (https://git.io/vbKK6) to the 'plugins' section of your Babel config to enable parsing.
Adding the @babel/plugin-syntax-import-meta to webpack.config.js leads to:
Module parse failed: Unexpected token (5:219)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
The notebook I’m trying to embed contains two file uploads and the error messages listed above seem to be referring to parts of the code where the file uploads happen. Did you managed to successfully embed a notebook with file uploads in your gatsby blog?
Hi @hbot! I ran into the same problem when importing an observable notebook in Gatsby. Did you eventually figure out how to get around the import.meta issue?
copy the json file from the node_modules/[your_directory]/files directory into create react app’s /public directory, give it an extension of .json (it has no extension by default), and then edit the javascript in the node_modules/[your_directory]/[your_file].js file so that the import is, for example:
new Map([["flare-2@2.json","/files/af12b2c45618d5de452c00b06fedb7419a7733e49ba65d051f45b3f9c754b41b842343db07d77422daa2137734c5eb09737342b5a5dda9ca509055fcd8f9a758.json"]]);
instead of:
new Map([["flare-2@2.json",new URL("./files/af12b2c45618d5de452c00b06fedb7419a7733e49ba65d051f45b3f9c754b41b842343db07d77422daa2137734c5eb09737342b5a5dda9ca509055fcd8f9a758",import.meta.url)]]);