🏠 back to Observable

Can a class defined in a notebook be imported?

It’s not clear from the Introdution to Imports discussion if an import of the following class into another notebook should work-or-not:

Import Syntax:

import {bezierPath} from “https://observablehq.com/@mariodelgadosr/animated-three-js-3d-quadratic-bezier-curves

Error being generated is: TypeError: errorloading dynamically imported module

In your import statement, you only need to include the notebook id (the “@user/notebook” part), and not the entire link. This alone should work:

import {bezierPath} from "@mariodelgadosr/animated-three-js-3d-quadratic-bezier-curves"

Notebook: https://observablehq.com/d/b867e4db566426c1

1 Like

To add to that, you can import from a URL, but for notebooks on observablehq.com you have to use the api.observablehq.com link:

import { bezierPath } from "https://api.observablehq.com/@mariodelgadosr/animated-three-js-3d-quadratic-bezier-curves.js?v=3"



If I’m not mistaken you can only import from Observable notebooks, because import only mimics static imports and is parsed/transpiled by Observable - correct?

Yes, that’s correct. To be precise, you’re not importing the notebook directly, but rather the compiled Observable v3 module. And any v3 module file can be imported, it doesn’t have to be hosted at observablehq.com.