Summary
marimo's anywidget loader only recognises a widget ESM that has a default
export. An ESM that exposes its lifecycle via the legacy named export —
export function render({ model, el }) { ... }
is rejected with a generic, hard-to-diagnose error:
Module at ./@file/<hash>.js does not appear to be a valid anywidget
anywidget's own runtime still loads this named-export form (it's deprecated, so
it emits a console deprecation warning, but it renders). The same widget that
works in Jupyter / JupyterLab therefore fails to render in marimo.
Two separate asks:
- Error message — make it actionable.
- Compat — optionally accept the deprecated named
render/initialize
export for parity with anywidget's runtime.
Environment
marimo 0.23.10
anywidget 0.11.0
Steps to reproduce
Any anywidget whose _esm uses the legacy named export, e.g.:
import anywidget, traitlets
class W(anywidget.AnyWidget):
_esm = """
export function render({ model, el }) {
el.textContent = "hello from named render";
}
"""
W()
Requested changes
1. Improve the error message
The current message gives the user no path forward. Inspect the imported module
and say why it failed and what to do — for example:
The module at <url> is not a valid anywidget front-end module: it has no
default export. Export your widget as export default { render } (see
https://anywidget.dev/en/afm/). Note: a bare export function render is the
deprecated anywidget API and is not supported here.
Even just detecting "module has a named render/initialize but no default
export" and emitting a targeted hint would save a lot of debugging.
2. (Optional) Accept the deprecated named export
To match anywidget's own loader, Px could also accept top-level
render/initialize named exports as a fallback, e.g.:
function isValidAnywidget(t) {
const d = t.default;
if (d) {
return typeof d === "function"
|| typeof d?.render === "function"
|| typeof d?.initialize === "function";
}
// Backward-compat with anywidget's deprecated named-export API.
return typeof t.render === "function" || typeof t.initialize === "function";
}
Related to fsspec/projspec#103
Summary
marimo's anywidget loader only recognises a widget ESM that has a default
export. An ESM that exposes its lifecycle via the legacy named export —
is rejected with a generic, hard-to-diagnose error:
anywidget's own runtime still loads this named-export form (it's deprecated, so
it emits a console deprecation warning, but it renders). The same widget that
works in Jupyter / JupyterLab therefore fails to render in marimo.
Two separate asks:
render/initializeexport for parity with anywidget's runtime.
Environment
marimo0.23.10anywidget0.11.0Steps to reproduce
Any anywidget whose
_esmuses the legacy named export, e.g.:Requested changes
1. Improve the error message
The current message gives the user no path forward. Inspect the imported module
and say why it failed and what to do — for example:
Even just detecting "module has a named
render/initializebut no defaultexport" and emitting a targeted hint would save a lot of debugging.
2. (Optional) Accept the deprecated named export
To match anywidget's own loader,
Pxcould also accept top-levelrender/initializenamed exports as a fallback, e.g.:Related to fsspec/projspec#103