3

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.

2

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

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

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`)
VALUES
(7,1,'Vendor/themename','Themename','preview_image_5aa8056a4f791.jpeg',0,'frontend',0,'Vendor/themename');

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 '18 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. – MagentoMan May 3 at 14:34
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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