observablehq / feedback

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

Import loads node version of a package #404

Open domoritz opened 2 years ago

domoritz commented 2 years ago

When I load import("apache-arrow@7"), Observable loads https://unpkg.com/apache-arrow@7?module which resolves to https://unpkg.com/apache-arrow@7.0.0/Arrow.node.mjs?module instead of https://unpkg.com/apache-arrow@7.0.0/Arrow.dom.mjs?module. I would expect Observable to load the dom version since the package.json specifies that Arrow.node.mjs should resolve to Arrow.dom.mjs in browser environments. Unfortunately, I cannot change the way the library is imported since it's transitively imported.

I filed an issue with unpkg at https://github.com/mjackson/unpkg/issues/325 but haven't heard back.

domoritz commented 2 years ago

esm.run works fine (https://cdn.jsdelivr.net/npm/apache-arrow@7/+esm). Would you consider switching to it?

mbostock commented 2 years ago

I would like to switch to esm.run or skypack.dev, but we don’t want to change the behavior of existing notebooks. I recommend specifying a full URL instead of using a bare module specifier. In the future we may have standard library versioning that would let us change the behavior in new notebooks or on an opt-in basis.

domoritz commented 2 years ago

Makes sense. Since Arrow is a transitive dependency in my case, the user has to use a fully qualified import for the main dependency. It seems to work fine (import("https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@1.13.1-dev285.0/+esm")).

For Arrow itself, instead of import('apache-arrow') I will recommend require('apache-arrow@7') or import("https://cdn.jsdelivr.net/npm/apache-arrow@7/+esm").

mbostock commented 2 years ago

Also note that Apache Arrow is part of our recommended libraries, so you can reference Arrow in a notebook without needing to import it. That said, we may be stuck on Apache Arrow 4.x if there are non-backwards-compatible changes in subsequent major versions. (In the future, we also plan on having version pinning for this.)

domoritz commented 2 years ago

We made some significant API changes in v7. v6 should be very similar/be compatible with v5 and v4, though, I think. Arrow does major releases every 3 months so a new version doesn't mean it has breaking changes.