Skip to content

anywidget loader rejects legacy named render export; error message is unhelpful #9972

Description

@Light2Dark

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:

  1. Error message — make it actionable.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions