reflex-dev/reflex · error · ValueError
the function names should be str names of functions in the s
Error message
the function names should be str names of functions in the specified transformer: {library!r} What it means
Raised by reflex_components_code.shiki_code_block.create_transformer when one of the function names passed in `fns` is not a Python str. The transformer API compiles function names into FunctionStringVar instances, so only string names of exported functions in the target transformer library are accepted.
Source
Thrown at packages/reflex-components-code/src/reflex_components_code/shiki_code_block.py:668
return imports
@classmethod
def create_transformer(cls, library: str, fns: list[str]) -> ShikiBaseTransformers:
"""Create a transformer from a third party library.
Args:
library: The name of the library.
fns: The str names of the functions/callables to invoke from the library.
Returns:
A transformer for the specified library.
Raises:
ValueError: If a supplied function name is not valid str.
"""
if any(not isinstance(fn_name, str) for fn_name in fns):
msg = f"the function names should be str names of functions in the specified transformer: {library!r}"
raise ValueError(msg)
return ShikiBaseTransformers(
library=library,
fns=[FunctionStringVar.create(fn) for fn in fns], # pyright: ignore [reportCallIssue]
)
def _render(self, props: dict[str, Any] | None = None):
"""Renders the component with the given properties, processing transformers if present.
Args:
props: Optional properties to pass to the render function.
Returns:
Rendered component output.
"""
# Ensure props is initialized from class attributes if not provided
props = props or {
attr.rstrip("_"): getattr(self, attr) for attr in self.get_props()
}View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Pass the names of the transformer functions as plain strings, e.g. fns=['rehypeSlug']
- If building fns programmatically, coerce each entry with str(fn) only if it really is a name
- Check for None entries before calling create_transformer
Example fix
// before
create_transformer("rehype-slug", fns=[rehype_slug])
// after
create_transformer("rehype-slug", fns=["rehypeSlug"]) Defensive patterns
Strategy: validation
Validate before calling
fns = [fn for fn in fns if fn is not None] assert all(isinstance(fn, str) for fn in fns), fns
Type guard
def is_fn_names(fns: list) -> bool:
return all(isinstance(fn, str) for fn in fns) Prevention
- Always quote transformer function names as strings
- Lint for non-str entries when building fns dynamically
When it happens
Trigger: Calling create_transformer('rehype-remark', fns=[SomeFunction]) or passing a callable, None, or imported function object instead of the string function name in the `fns` list.
Common situations: Developers import a transformer function directly (e.g. `import rehypeSlug from ...`) and pass the imported object instead of the string 'rehypeSlug'; or they build the fns list dynamically and accidentally include None.
Understand the failure class
Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.
Related errors
- reflex.Config.plugins must contain Plugin instances, but got
- Invalid plugin class: {plugin_name!r} for {field_name}. Must
- Invalid type for environment variable {field_name}: {field_t
- Unexpected event type, {type(e)}.
- Color is not a valid color.
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/4f68d8b75b413c7a.
Report an issue: GitHub.