octobercms/october · error · SystemException

The component code viewBag is reserved. Please use another…

Error message

The component code viewBag is reserved. Please use another code for the component class %s.

What it means

Registration guard in ComponentManager::registerComponent: the component code (alias) 'viewBag' is hard-reserved for Cms\Components\ViewBag; any other plugin class attempting to register under that code is rejected during plugin bootstrap.

Solutions

  1. Register the component under a different code/alias
  2. Rename the plugin's component declaration in its pluginDetails/components registration
  3. If you need view-bag behavior, extend Cms\Components\ViewBag instead
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/cms/classes/ComponentManager.php:124 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/d4f81905135f0d17. Report an issue: GitHub.

Appendix: source

Thrown at modules/cms/classes/ComponentManager.php:124

    /**
     * registerComponent registers a single component.
     */
    public function registerComponent($className, $code = null, $owner = null)
    {
        if (!$this->classMap) {
            $this->classMap = [];
        }

        if (!$this->codeMap) {
            $this->codeMap = [];
        }

        if (!$code) {
            $code = Str::getClassId($className);
        }

        if ($code === 'viewBag' && $className !== \Cms\Components\ViewBag::class) {
            throw new SystemException(sprintf(
                'The component code viewBag is reserved. Please use another code for the component class %s.',
                $className
            ));
        }

        $className = Str::normalizeClassName($className);
        $this->codeMap[$code] = $className;
        $this->classMap[$className] = $code;

        if ($owner !== null) {
            if ($owner instanceof \System\Classes\PluginBase) {
                $this->setComponentOwnerAsPlugin($code, $className, $owner);
            }
            else {
                $this->setComponentOwnerAsProvider($code, $className, $owner);
            }
        }
    }

View on GitHub (pinned to b608633a7e)