Fix Magento generated code and pub/static

Missing files under generated/ and a permission error while moving pub/static are deploy failures. Compile and deploy as a user who can write those directories.

Last updated: October 26, 2026

generated/ holds factories, proxies, and interceptors that setup:di:compile writes. pub/static holds the CSS and JavaScript the browser loads. When either tree is half-deleted, owned by the wrong user, or deployed in the wrong mode, Magento includes files that are not there or refuses to publish new ones.

Illustration of a missing generated Interceptor file and a FileSystemException for pub/static.
Illustration. A missing generated class and a static-file stat failure are different messages. This is not a capture from a shop.

These are deploy failures. They are not fixed by adding a column to a content table or by clearing the browser cache alone.

Errors

Warning: include(.../generated/code/...): Failed to open stream
Failed to open stream: No such file or directory (.../registration.php)
Magento\Framework\Exception\FileSystemException: Cannot gather stats
mv: cannot move 'pub/static' to 'pub/static_bak/static': Permission denied

Cannot gather stats means PHP stat() failed for a path Magento expected to exist, often a static file named in the error. Permission denied on mv means the user running deploy cannot rename that directory. The web server user and the deploy user are not the same person.

See the mode first

php bin/magento deploy:mode:show

Developer mode writes static files when the browser asks, and it does not want a full setup:static-content:deploy unless you pass -f. Production mode serves only what that command published. Compiling and deploying while the site is in the wrong mode explains a shop that works for you in a terminal and 404s for customers.

Put generated code back

From the Magento root, during a maintenance window:

php bin/magento maintenance:enable
rm -rf generated/code generated/metadata var/cache var/page_cache var/view_preprocessed
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento maintenance:disable

Windows PowerShell does not have rm -rf:

Remove-Item -Recurse -Force generated\code, generated\metadata, var\cache, var\page_cache, var\view_preprocessed
php bin/magento setup:upgrade
php bin/magento setup:di:compile

Put the site in maintenance mode before you delete generated/ on a shop that is serving customers. Do not delete generated/ on a live production box in the middle of traffic. Requests that arrive before compile finishes throw the same include warnings you are trying to cure. Do not delete var/log if you still need the error, and do not delete app/etc/env.php.

registration.php missing under vendor/ is not a generated-code problem. composer install has not finished, or vendor/ was deleted. Restore it from composer.lock before compiling:

composer install --no-dev

--no-dev belongs on production. Locally, omit it if you need dev tools.

Publish static files

Production, from a user who can write pub/static:

php bin/magento setup:static-content:deploy en_US

Add every locale the stores use. A German storefront with only en_US deployed still 404s de_DE files, which then shows up as Cannot gather stats for a path under de_DE.

pub/static is the directory browsers request. generated/code is the directory PHP includes. A 404 for styles.css is the first. A missing factory class is the second. Deploying static files does not create factories, and setup:di:compile does not publish CSS. Run the command that matches the missing path. On Windows, deploy with --strategy=copy. The symlink strategy needs a privilege most local Apache accounts do not have, and a failed symlink looks like an empty theme.

If deploy cannot move pub/static aside:

ls -ld pub pub/static

The owner must be the user running PHP, or that user must be in the group and the directory must be group-writable. Do not chmod 777. On a typical two-user setup, deploy as the same user php-fpm uses, or grant the group write and set the setgid bit on pub/static and var so new files stay in that group.

The chmod calculator shows the same mode as a number and as a command. Do not use 777.

Developer mode: skip the deploy, flush cache, and reload. If you already deployed with -f in developer mode, Magento stops generating files until you remove the deployed sign. Removing pub/static/deployed_version.txt after a bad deploy lets developer mode take over again. Do that only in developer mode.

Check the result

  • php bin/magento setup:di:compile exits 0.
  • A storefront CSS URL under pub/static/frontend/... returns 200.
  • var/log/exception.log has no new FileSystemException for that CSS path.
  • ls pub/static/frontend shows your theme and locale, not only Magento/blank.

If that does not work

  • Compile runs out of memory. Raise the CLI memory_limit for that process. That is a separate fault from a missing file.
  • pub/static is a symlink into a release directory the current user cannot rename. Fix the release layout. Do not copy the symlink target over itself.
  • The theme’s registration.php or theme.xml is missing, so deploy skips it and the admin cannot select it. Restore the theme before deploying again.
  • Windows created pub/static files that Linux cannot read after a zip copy, because of a path that was too long. Deploy on the server. Do not upload pub/static from a Windows working copy.

References

On this page

Related Tools

Related Articles

Need a tool for this ?

Open the free tools — no signup.

FAQs

Innovative Solutions For Modern Needs
Copyright © 2026 Yallasolve. all rights reserved.