Base theme stable9 has not been installed

When working on developing a custom theme in part 2 of my Drupal Theme primer series, Using Stable and Classy as Base Themes, I come across a strange bug in that when I tried to set Stable 9 as the base theme I got the following error.

Drupal\Core\Theme\MissingThemeDependencyException: Base theme stable9 has not been installed. in Drupal\Core\Theme\ThemeInitialization->getActiveThemeByName() (line 122 of core/lib/Drupal/Core/Theme/ThemeInitialization.php)

I was getting a white screen on trying to set the base theme: stable9 in the theme info YAML. Luckily I could still access the recent log messages in the UI to see the error.

This seemed like a strange error as since Drupal 9 the base theme is a required key. Since Stable 9 comes with Drupal I decided to manually enable it. Since Stable 9 is hidden in the UI I had to first go into the theme and comment out the hidden: true key-value pair. I was then able to manually enable Stable 9 in the UI and to my surprise this did work.

This, however, was not really a solution and after a little more testing I worked out that for some reason the Drupal theme registry seems to get "stuck". This doesn't seem to be documented anywhere but I found that if you change the name of your theme or try to install on another instance the install works.

So that's it, if you ended up here through a search then hopefully this small hack will also work for you.