Fatal Error defining extension

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Silverstripe Version: 4.4.4

Question:

I have written an extension and when I added it to Page in app.yml I incorrectly typed the namespace and ran dev/build. Unsurprisingly this resulted in a Fatal Error:

Fatal error: Uncaught InvalidArgumentException: Page references nonexistent MyNamespace\Extensions\MyClassExtension in 'extensions' in C:\xampp\htdocs\_webroots\ss\vendor\silverstripe\framework\src\Core\Config\Middleware\ExtensionMiddleware.php:70 Stack trace: #0 C:\xampp\htdocs\_webroots\ss\vendor\silverstripe\framework\src\Core\Config\Middleware\ExtensionMiddleware.php(41): SilverStripe\Core\Config\Middleware\ExtensionMiddleware->getExtraConfig('Page', Array, 0) #1 C:\xampp\htdocs\_webroots\ss\vendor\silverstripe\config\src\Middleware\MiddlewareAware.php(56): SilverStripe\Core\Config\Middleware\ExtensionMiddleware->getClassConfig('Page', 0, Object(Closure)) #2 C:\xampp\htdocs\_webroots\ss\vendor\silverstripe\framework\src\Core\Config\Middleware\InheritanceMiddleware.php(30): SilverStripe\Config\Collections\MemoryConfigCollection->SilverStripe\Config\Middleware\{closure}('Page', 0) #3 C:\xampp\htdocs\_webroots\ss\vendor\silverstripe\config\src\Middleware\MiddlewareAware.php(56): SilverStripe\Core\Config\Middlewar in C:\xampp\htdocs\_webroots\ss\vendor\silverstripe\framework\src\Core\Config\Middleware\ExtensionMiddleware.php on line 70

I have since corrected the typo, but I cannot run dev/build as my webserver is stuck on this error. Even if I remove app/src/MyClassExtension.php and the reference to it in app.yml I get the same fatal error when trying to access the site.

Any ideas on how I can get passed this?
Where is this path ‘MyNamespace\Extensions\MyClassExtension’ cached?

Thanks,
Olly

Fixed by setting the environment to dev in the .env file.

I thought I had set this already, but of course it was a different pc and this file is in .gitignore…

User error as always :crazy_face:

That’s the solution for dev environments.

For production there are 3 other options yet (in case this happens to someone on prod and they come here from google):

  • Quick way = do cli based flush (sake dev/build). Although, the user must be the same one that runs webserver, otherwise it’ll generate and clean different cache from what webserver uses.
  • No access to the server way (e.g. upload scripts through only sftp or rsync) = use SS_FLUSH_ON_DEPLOY
  • The best way = do not reuse cache between deployments. Use different cache folders for every deployment, then you won’t have to flush on production.