{"record":{"id":"cdb4af75c1343c31","repo":"reflex-dev/reflex","slug":"var-returning-rx-memo-func-name-cannot-impo","errorCode":null,"errorMessage":"Var-returning `@rx.memo` `{func_name}` cannot import `{lib}` because it is not bundled. Use a component-returning `@rx.memo` instead.","messagePattern":"Var-returning `@rx\\.memo` `(.+?)` cannot import `(.+?)` because it is not bundled\\. Use a component-returning `@rx\\.memo` instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/components/memo.py","lineNumber":830,"sourceCode":"            f\"Var-returning `@rx.memo` `{func_name}` cannot depend on embedded \"\n            \"components, custom code, or dynamic imports. Use a component-returning \"\n            \"`@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n    bundled_libraries = RegistrationContext.ensure_context().bundled_libraries\n    for lib in dict(var_data.imports):\n        if not lib:\n            continue\n        if lib.startswith((\".\", \"/\", \"$/\", \"http\")):\n            continue\n        if format.format_library_name(lib) in bundled_libraries:\n            continue\n        msg = (\n            f\"Var-returning `@rx.memo` `{func_name}` cannot import `{lib}` because \"\n            \"it is not bundled. Use a component-returning `@rx.memo` instead.\"\n        )\n        raise TypeError(msg)\n\n\ndef _rest_placeholder(name: str) -> RestProp:\n    \"\"\"Create the placeholder RestProp.\n\n    Args:\n        name: The JavaScript identifier.\n\n    Returns:\n        The placeholder rest prop.\n    \"\"\"\n    return RestProp(_js_expr=name, _var_type=dict[str, Any])\n\n\ndef _var_placeholder(\n    name: str,\n    annotation: Any,\n    runtime_value: Any | None = None,","sourceCodeStart":812,"sourceCodeEnd":848,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/components/memo.py#L812-L848","documentation":"A Var-returning `@rx.memo` produced a Var whose data imports a JavaScript library that is not registered as bundled in the current `RegistrationContext`. Var-returning memos compile to inline expressions and can only rely on libraries that are bundled with the app. Reflex raises this TypeError at decoration time listing the offending import.","triggerScenarios":"The memo body uses a Var operation (e.g. `.to_number()`, `.to_string()`, custom JS via `rx.Var.operation` or `rx.utils.format`) whose VarData imports a lib like `datetime`/`react-icons/...` that starts with `.`, `/`, `$/`, or `http` or is otherwise absent from `bundled_libraries`, so the `format.format_library_name(lib) in bundled_libraries` check fails.","commonSituations":"Using icon libraries or third-party npm imports inside a Var-returning memo; memoizing a function that calls a custom Var hook pulling in a CDN/URL import; forgetting to import/install the library (e.g. `import reflex_icon_library`) so it never gets registered as bundled.","solutions":["Convert the memo to component-returning (`-> rx.Component`), which supports arbitrary library imports","Ensure the library is bundled: install it via its Reflex package and import that module (e.g. `import reflex_icon_library`) before the memo is evaluated so it appears in `RegistrationContext.bundled_libraries`","Refactor the memo body to avoid the operation that pulls in the unbundled import"],"exampleFix":"// before\n@rx.memo\ndef label(icon: rx.Var[str]) -> rx.Var[str]:\n    return icon + \"!\"  # VarData imports an unbundled icon lib\n\n// after\nimport reflex_icon_library  # registers the lib as bundled\n\n@rx.memo\ndef label(icon: rx.Var[str]) -> rx.Var[str]:\n    return icon + \"!\"","handlingStrategy":"validation","validationCode":"import reflex as rx\nfrom reflex_base.compiler.registration_context import RegistrationContext\n\nlib = \"react-icons/fa\"  # the lib your memo pulls in\nbundled = RegistrationContext.ensure_context().bundled_libraries\nassert lib in bundled or any(l.endswith(lib) for l in bundled), f\"{lib} not bundled; import its installer first\"","typeGuard":"def is_bundled(lib: str, bundled: set[str]) -> bool:\n    from reflex.utils.format import format_library_name\n    return format_library_name(lib) in bundled","tryCatchPattern":"try:\n    @rx.memo\n    def value_memo(...) -> rx.Var[str]: ...\nexcept TypeError as e:\n    if \"it is not bundled\" in str(e):\n        raise  # or convert the memo to component-returning","preventionTips":["Import library installer modules (e.g. `import reflex_icon_library`) at the top of the app module before memos are evaluated","Prefer component-returning memos when the body needs third-party npm libraries","Check the error message: it names the exact unbundled lib"],"tags":["reflex","rx-memo","typeerror","imports","bundled-libraries"],"backgroundTag":"decorator-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}