-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS error when loading embedded HTML output on Anywidget #369
Comments
Ok my head is spinning but I somewhat got it to work..? It's actually a bundling issue because assign(Hammer, {
INPUT_START: INPUT_START2,
INPUT_MOVE: INPUT_MOVE2,
...
});
var freeGlobal = typeof window3 !== "undefined" ? window3 : typeof self !== "undefined" ? self : {};
freeGlobal.Hammer = Hammer;
if (typeof define === "function" && define.amd) {
define(function() {
return Hammer;
});
} else if (typeof module2 != "undefined" && module2.exports) {
module2.exports = Hammer;
} else {
window3[exportName] = Hammer;
}
})(window, document, "Hammer");
}
}); If we manually change this to: - if (typeof define === "function" && define.amd) {
- define(function() {
- return Hammer;
- });
- } else if (typeof module2 != "undefined" && module2.exports) {
+ if (typeof module2 != "undefined" && module2.exports) {
module2.exports = Hammer;
} else {
window3[exportName] = Hammer;
} Then it works. 🤯 (
) It seems that it's different outside of a notebook because |
Ah yes, this was my suspicion (some runtime detection of globals). I think you can configure esbuild to eliminate that if block with define. import esbuild from "esbuild";
esbuild.build({
entryPoints: [
"./src/index.tsx",
],
bundle: true,
minify: true,
target: ["es2020"],
outdir: "lonboard/static/",
format: "esm",
define: {
'define.amd': 'false',
},
}); |
🤯 I can't believe it, that just worked. Thanks so much! |
Hi @kylebarron and @manzt, I'm having an issue importing deck.gl from esm.sh in certain Jupyter notebook contexts (namely Terra.bio vs Google Colab) and the issue seems to be related to this issue (e.g., hammer.js). Please let me know if you all have any ideas on what might be going wrong. |
I've never tried to use deck from |
I would recommend using esbuild with the configuration I mentioned above. Deck seems like a tricky dependency and passing off bundling to a CDN services is inconsistent, for exactly the same reason Kyle had above: |
It's not clear that the ultimate issue here is in Anywidget, but I figured it would be ok to start with an issue here. I'm making lonboard as a fast map rendering library and widget. It would be nice to support standalone HTML export and nbconvert conversion to HTML. When I create a minimal map, e.g. with:
The map renders fine within Jupyter Notebook:
But loading the exported HTML fails with
That's specifically coming from a bundled library that's a dependency of mine (via deckgl).
It's weird that this works fine in the notebook but not standalone. My hunch is that there's a difference in how the JS gets run inside the notebook vs as a standalone file.
If we look at what
ipywidgets.embed.embed_minimal_html
does, it's described here and essentially creates:So it uses standard script tags for
require.js
and@jupyter-widgets/html-manager
as well as for the custom widget state. I imagine there must be some difference in the above generated HTML that means the anywidget code isn't getting run as ESM...? (I'm definitely not an expert on this part of JS).As repro, I'm attaching a zipfile with
minimal.ipynb
that has the same Python code as above, andminimal.html
with the export. This is using lonboard 0.2.0 but with minify set tofalse
so the exported HTML can be somewhat readable.minimal.zip
The text was updated successfully, but these errors were encountered: