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.

  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.

5 Answers 5


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

  • This should be the correct answer. +1 May 3, 2019 at 14:34
  • Thanks You are right
    – Sourav
    May 21, 2019 at 8:38

I was facing the same problem after creating a custom theme.

Whenever I tried to deploy the static content using command:

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

I was facing an error saying:

Cannot read contents from file ...... etc.

After debugging, I found that in the theme table of my database.. The parent_id for the newly created theme was NULL. I changed that to the required Parent Theme Id that was 4 in my case. After that I used the static content deploy command again and It worked with no issues.

  • It works great after updating database 2.1 to 2.2!
    – chdzma
    Dec 9, 2019 at 13:26

EDIT: This describes why it was failing and a way to work around it, but JNDPNT/Altravista has the right answer so I updated. Trouble is, we want to run setup:upgrade as late in the deploy process as possible - in the chance something happens to bail the deploy, allows easier rollback than after setup:upgrade has run. It's unfortunate to have to change this flow just for the very infrequent case of deploying a new theme. END EDIT

Turned out that the theme database table didn't have an entry for the new theme. So the deploy to staging pushed the code but didn't create update the database, and the second dev copied the database from staging so also didn't have the entry. I don't know off hand what creates the entry, if simply setting and saving the theme via admin will create it or something else is required. However, after adding an entry:

INSERT INTO `theme` (`theme_id`, `parent_id`, `theme_path`, `theme_title`, `preview_image`, `is_featured`, `area`, `type`, `code`)

I don't know yet if there is a way to cause this to be automatically created when making a new theme, but should only need to be done once per new theme.

  • 1
    For people like me who strand on the article via google: You need to run php/bin magento setup:upgrade first.
    – JNDPNT
    Jul 13, 2018 at 17:38
  • This is not the correct method. See Altravista's answer. You should run bin/magento setup:upgrade before compiling to resolve the issue. May 3, 2019 at 14:34
  1. Go to Admin panel, in menu Content -> Design -> Configuration
  2. Click to Edit your theme in list
  3. Click Save Configuration

I also had the same issue.

How I fixed it:

Found that one of my .less file has syntax error.

That was the reason why .css files were not generating from .less files.

fixed the syntax error.

Also, fixed error: undefined error @media-common is not defined.

Then fired command:

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

And style-l.css and other .css files are generated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.