Custom Theme – Fix styles-m.css Failed to Open Stream Error

custom-themestatic-content

When setting up a new custom theme that has Magento/blank as a parent, we were able to deploy static assets locally but deploying to our staging site failed with an error.

[Magento\Framework\Exception\FileSystemException]
  Cannot read contents from file "/vagrant/site.dev.vendor.com/www/pub/static/frontend/Vendor/themename/en_US/css/styles-m.css" Warning!file_get_contents(/vagrant/site.dev.vendor.com/www/pub/static/frontend/Vendor/themename/en_US/css/styles-m.css): failed to open stream: No such file or directory

It feels as though the parent theme fallback is not functioning like it should, digging back through the output to php bin/magento setup:static-content:deploy shows that it is failing on a bunch of different less, css, and js files. The final error that comes out just lists styles-m.css.

We had a second developer set up the site in an identical environment as the first, and they also got the error in both production and developer modes.

Best Answer

when you create a new theme you need to run bin/magento setup:upgrade before deploy