reflex-dev/reflex · error · SystemExit

For `{template_name}` template, `template_code_dir_name` and

Error message

For `{template_name}` template, `template_code_dir_name` and `template_dir` should both be provided.

What it means

Raised by `reflex.utils.templates.initialize_app_directory` when a non-default template is requested but its location on disk is not fully specified. Custom templates are not bundled, so Reflex requires BOTH template_code_dir_name and template_dir to locate the code; providing only one is ambiguous and the app cannot be scaffolded.

Source

Thrown at reflex/utils/templates.py:74

        SystemExit: If template_name, template_code_dir_name, template_dir combination is not supported.
    """
    logger.info("Initializing the app directory.")

    # By default, use the blank template from local assets.
    if template_name == constants.Templates.DEFAULT:
        if template_code_dir_name is not None or template_dir is not None:
            logger.error(
                f"Only {template_name=} should be provided, got {template_code_dir_name=}, {template_dir=}."
            )
            raise SystemExit(1)
        template_code_dir_name = constants.Templates.Dirs.CODE
        template_dir = Path(constants.Templates.Dirs.BASE, "apps", template_name)
    else:
        if template_code_dir_name is None or template_dir is None:
            logger.error(
                f"For `{template_name}` template, `template_code_dir_name` and `template_dir` should both be provided."
            )
            raise SystemExit(1)

    logger.debug(f"Using {template_name=} {template_dir=} {template_code_dir_name=}.")

    # Remove __pycache__ dirs in template directory and current directory.
    for pycache_dir in [
        *template_dir.glob("**/__pycache__"),
        *Path.cwd().glob("**/__pycache__"),
    ]:
        shutil.rmtree(pycache_dir, ignore_errors=True)

    for file in template_dir.iterdir():
        # Copy the file to current directory but keep the name the same.
        path_ops.cp(str(file), file.name)

    # Rename the template app to the app name.
    path_ops.mv(template_code_dir_name, app_name)
    path_ops.mv(
        Path(app_name) / (template_name + constants.Ext.PY),

View on GitHub (pinned to 45b8ed5ab7)

Solutions

  1. Provide both template_code_dir_name (e.g. 'code' or the subdir inside the template containing the app) and template_dir (absolute or relative path to the extracted template).
  2. If you wanted the bundled starter, use template_name=constants.Templates.DEFAULT with no extra args.

Example fix

# before
initialize_app_directory(template_name="crypto_dashboard")

# after
initialize_app_directory(
    template_name="crypto_dashboard",
    template_dir=Path("/tmp/unpacked/crypto_dashboard"),
    template_code_dir_name="code",
)
Defensive patterns

Strategy: validation

Validate before calling

from reflex import constants

def validate_template_args(name, code_dir_name, template_dir):
    if name != constants.Templates.DEFAULT:
        assert code_dir_name is not None and template_dir is not None, (
            "custom templates need both template_code_dir_name and template_dir"
        )

Prevention

When it happens

Trigger: Calling initialize_app_directory(template_name="my_template") with template_code_dir_name=None or template_dir=None (or omitting one of them). Reached via create_config_init_app_from_remote_template after downloading a template zip whose layout didn't yield the expected values.

Common situations: Passing a custom template name without its directory; a remote template download path failing to populate template_dir before initialization is called.

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/d0b1411a9fe07589. Report an issue: GitHub.