I love this tool. What I really like is the fact that a cell in a notebook can be imported as a function as you would do with packages (cell->cell) and of course loading npm packages (npm->cell). However, it is not as easy to do the other way around (cell->npm).
It would be amazing if we could export notebooks as npm modules and use them in the same easy way, importing other notebooks works here.
The problem that I encounter is the following: I want to be able to just export a notebook and use the function that I defined in it, without doing any crazy runtime scripting. What I end up doing instead to avoid this issue is to copy paste the code in a new npm module and import this module in the notebook.
nicola@nicolaprotocol ~/H/o/n/downloading-and-embedding-notebooks> node downloading-and-embedding-notebooks.js
/Users/nicola/Hacks/observablehq-scripts/node_modules/downloading-and-embedding-notebooks/downloading-and-embedding-notebooks.js:242
export default notebook;
^^^^^^
SyntaxError: Unexpected token export
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:279:19)
lol! that notebook doesnât exist on observablehq it was simply a template for export notebook url signature.
Pick a notebook that you want to export and add to your JS project as a module, then right-click on Download tarball to Copy Link to your notebook module url.
Sorry for the delay in answering. Your evaluation of the current state is pretty much on point: we support loading from npm, cross-importing from Observable, and also running Observable notebooks on the web using the notebook runtime, but exporting notebooks as npm modules that can run with Node.js isnât yet easy or straightforward. Partially this is because most notebooks require and rely on the web - whether itâs generating HTML or SVG elements, using fetch() to load data, or many other bits provided by the web platform. Unfortunately the Node.js platform and web platform are building sort of parallel futures currently.
So the current Notebook export format is made to work in browsers (which nearly all support the ES Module specification) rather than Node.js (which, unfortunately, doesnât, yet).
Stay tuned for future developments on this front - especially as Node.js ships ES Module support in 12.x, weâll be investing time to make Notebooks work well as springboards for Node.js module development.