observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

import issues #528

Closed martintelefont closed 1 year ago

martintelefont commented 1 year ago

Hi,

I want to start bundling a loose collection of functions I have been using over the past forever into javascript library that would ideally work in observablehq and in a normal html environment via <script .../>. I am having problems with the import into an observablehq notebook. I have tried making changes to the dummy code, but the last message got me scratching my head on what I should try next.

The notebook is this one: https://observablehq.com/d/c096c36d95dc6a4a The dummy code is here: https://github.com/martintelefont/test-repo

Any pointer to how to do this, or a baritone library I can fork and develop from would really help me out.

mootari commented 1 year ago

Hi Martin, jsdelivr is not a bundler, and I'm not aware of any bundler that doesn't require your package to be published to npm. You will either have to publish to npm (and then import via esm.sh or skypack) or include a bundled version in your repository files.

Please also note that support questions will find a larger audience when asked on our forum talk.observablehq.com.

mbostock commented 1 year ago

jsDelivr does provide an ES module bundler on top of npm: https://www.jsdelivr.com/esm

I recommend you use "type": "module" in your package.json. Here’s a relatively small repo to demonstrate: https://github.com/mbostock/isoformat

martintelefont commented 1 year ago

Thanks @mootari and @mbostock for the quick feedback. I found a way to make it work without a bundler.

test.mjs only as a single function in it, but it looks like it does the trick. https://github.com/martintelefont/test-repo/blob/main/test.mjs

I will look into both options (bundler + npm) and how to do it via the package.json in the coming weeks. But for now I am good and I can keep using observable as my test lab for functions :-)