Reflex

Common Errors

We've compiled a list of the most common errors users face when using Reflex. If you have encountered an error that isn't answered here, feel free to reach out to us on our Discord.

Object null is not iterable

Server Error

TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))

This is caused by using an older version of nodejs.

  • Ensure the latest version of Reflex is being used: pip install reflex --upgrade.
  • Remove the .web and ~/.reflex directories and re-run reflex init.

Hydration failed because the initial UI does not match

Unhandled Runtime Error

Error: Hydration failed because the initial UI does not match what was rendered on the server.

Often caused by incorrect nesting of components

  • Particularly <p> and <div>, but may also occur with tables
  • Ensure there are no nested rx.text or layout components within rx.text
  • Ensure that all tables use rx.table.header and rx.table.body to wrap the rx.table.row rows
No
rx.text(
    rx.text("foo")
)
rx.text(
    rx.box("foo")
)
rx.text(
    rx.center("foo")
)
rx.table.root(
    rx.table.row(
        rx.table.column_header_cell("Full name"),
    ),
)
Yes
rx.text("foo")
rx.box(
    rx.text("foo")
)
rx.center(
    rx.text("foo")
)
rx.table.root(
    rx.table.header(
        rx.table.row(
            rx.table.column_header_cell("Full name"),
        ),
    ),
)

See the hydration error troubleshooting guide.

Invalid var passed for prop

TypeError: Invalid var passed for prop href, expected type <class 'str'>, got value {state.my_list.at(i)} of type typing.Any.

Add a type annotation for list Vars

For certain props, reflex validates type correctness of the variable. Especially when de-referencing lists and dicts, it is important to supply the correct annotation.

class State(rx.State):
    # NO
    my_list = ["a", "b", "c"]

    # YES
    my_indexable_list: list[str] = ["a", "b", "c"]
  • Add type annotations to all state Vars.

TypeError: metaclass conflict (SQLModel)

Python Error

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

This is caused by importing sqlmodel earlier than reflex.

  • Ensure that reflex is imported before sqlmodel.

ImportError: couldn't import psycopg

Import Error

ImportError: couldn't import psycopg 'python' implementation: libpq library not found | couldn't import psycopg 'binary' implementation: No module named 'psycopg_binary' | couldn't import psycopg 'c' implementation: No module named 'psycopg_c'

This is caused by not installing the correct psycopg package. Solution is to add the psycopg[binary]==3.2.3 package to your requirements.txt file.

Build with Reflex.