Observableās require uses AMD, so youāll need to generate an AMD-compatible bundle rather than targeting CommonJS. (UMD is recommended.)
If your AMD bundle doesnāt work with require, Iād be happy to take a look, but youād need to share the generated code, say by attaching the bundle as a file attachment to a notebook and then sharing that notebook. If you donāt want to share this code publicly you are welcome to email us at support.
Also, I think some browsers wonāt let you access HTTP servers from Observable (which uses HTTPS exclusively). Though it appears your browser allows it for localhost. You can avoid this, again, by attaching the generated bundle to your notebook as a file, e.g.:
@mbostock thank you for the reply!
Here is a repro as youāve recommended: Require Test
My goal is to develop a library in a TypeScript and use it in an Observable notebook. I thought that requiring it from a local server should work, but it turned out not to be so simple.
The reason this AMD bundle isnāt working is because itās generating multiple named AMD modules, whereas what you want is to generate a single unnamed module. Unfortunately, Iām not familiar with the TypeScript compiler, so I donāt know what options would be needed to generate an anonymous AMD module (which is the more common format).
You could maybe also try using the ES2015 output format, and then using a dynamic import instead of require.
and then using module = import(āurlā) in the notebook.
minor issues
needing to reload page rather than rerun cell to reload module
couldnāt get import {something} from āurlā format to work. (or import āurlā returning the default export)
Would be be possible to load the map file also? Perhaps they can be packaged together?
At least for me, the idea of having typescript in an external editor (for āheavierā code) and then the notebook to work with it seems a great combo.
Thank you @carl, yes, the import is not working and it is a deal breaker. After spending too much time on it I just gave up. Observable is awesome for snippets but when your project grows (and now I have a second project in thousands of lines) the lack of a proper editor and types shows.