Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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.

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. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top