reflex-dev/reflex · error · ValueError

You must specify either children or src for the script…

Error message

You must specify either children or src for the script element.

What it means

rx.script requires exactly one source of script content: either inline children (the script body) or the `src` attribute pointing at an external file. Neither being present means there is nothing to render into the helmet script tag, so create() raises ValueError.

Solutions

  1. Provide inline code: rx.script("console.log('hi')")
  2. Or reference an external file: rx.script(src='/js/analytics.js')
  3. Guard conditional scripts: only call rx.script when the body string is non-empty

Example fix

// before
rx.script(src=None)  # nothing

// after
rx.script("console.log('hi')")
# or
rx.script(src="/js/analytics.js")
Defensive patterns

Strategy: validation

Validate before calling

assert children or src, "rx.script needs children or src"

Type guard

def has_script_source(children, src) -> bool:
    return bool(children) or bool(src)

Prevention

When it happens

Trigger: Calling rx.script() with no arguments, or rx.script(id='x', type='module') passing only attributes without children or src.

Common situations: Copy-pasting a script tag and stripping the body during refactor; conditionally building children that end up empty (e.g. "".join(parts) yielding nothing).

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28). Data as JSON: /api/errors/154b0406b5e4cc72. Report an issue: GitHub.

Appendix: source

Thrown at packages/reflex-components-core/src/reflex_components_core/base/script.py:56

        integrity = props.pop("integrity", None)
        referrer_policy = props.pop("referrer_policy", None)
        src = props.pop("src", None)
        type = props.pop("type", None)
        key = props.pop("key", None)
        id = props.pop("id", None)
        class_name = props.pop("class_name", None)
        custom_attrs = props.pop("custom_attrs", None)
        on_mount = props.pop("on_mount", None)
        on_unmount = props.pop("on_unmount", None)

        if props:
            logger.warning(
                f"rx.script does not support the following properties: {list(props.keys())}"
            )

        if not children and not src:
            msg = "You must specify either children or src for the script element."
            raise ValueError(msg)

        return helmet(
            elements.Script.create(
                *children,
                async_=async_,
                char_set=char_set,
                cross_origin=cross_origin,
                defer=defer,
                integrity=integrity,
                referrer_policy=referrer_policy,
                src=src,
                type=type,
                key=key,
                id=id,
                class_name=class_name,
                custom_attrs=custom_attrs,
                on_mount=on_mount,
                on_unmount=on_unmount,

View on GitHub (pinned to 45b8ed5ab7)