🏠 back to Observable

npm installing a notebook with dependencies

I’m experimenting with deploying an Observable notebook outside of Observable following this guide: https://pohewa.ws/posts/embedding-observable-notebooks/

Looking inside node_modules I see that there’s a single module, my notebook, and inside it is the code for that notebook, containing cells like these for import statements:

    {
      from: "@yurivish/common",
      name: "min",
      remote: "min"
    }, /* many more of these, including references to private notebooks */

Is there a way to add a notebook to a project bundled together with its transitive dependencies?

Are you using the old format? I recommend using v=3 as the current “Download tarball” link will give you.

1 Like

Aha, I was using the old format. The other thing is that there’s currently no error if you install a notebook with private dependencies — they just silently won’t get included. I’ve now tested with enabling sharing on one of them and it successfully installs.

Thanks for the guidance!

Now that I tried running the code, I’m seeing a “modules not iterable” error when I test this out with my notebook. The example notebook from the post works fine.

load.js:20 Uncaught TypeError: modules is not iterable
    at Function.load (load.js:20)
    at main.js:22
    at main.js:31
load @ load.js:20
(anonymous) @ main.js:22
(anonymous) @ main.js:31

Using the Chrome debugger I see that notebook is a function, rather than an object:

One difference is that my notebooks have circular dependencies — I have a “library” notebook that imports functions from other notebooks for re-export, and in a few cases the library notebook imports function A from some notebook which imports function B from the library notebook. Rollup gives me warnings about circular dependencies though I don’t know if it’s a problem, since everything works perfectly on observablehq.com.

Edit: It probably can’t be that, since there are circular dependencies within e. g. the inspector, not just my notebooks:

(!) Circular dependency: node_modules/@observablehq/inspector/src/collapsed.js -> node_modules/@observablehq/inspector/src/expanded.js -> node_modules/@observablehq/inspector/src/collapsed.js

Could you share the notebook / embedding code that you’re running into trouble with?

You appear to be calling Runtime.load, which was deprecated and not needed with the v=3 format. Please see the README for documentation on how to load a module:

2 Likes

Ah, the blog post I was following is just out of date. My apologies.

I now have my notebook running using the instructions in the README, but the majority of the cells report as “could not be resolved”, and it looks like those are some (but not all) of the cells imported from my library notebook.

I’ll see if I can make a reduced problematic case, or report back if I figure out what’s going on.