Hello everyone,
after a fresh installation of Magento 2, i see this one in my source code:
How may I fix this?
Thank you very much.
@ci2014 ... on which page?
@srenon on every page
<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />
I having same issue. I have two Magento 2 installations, one installed with sample data for testing, and other one without it.
One installation that contains sample data, I have no issues with it.
But, another installation without sample data throws that 404 message
http://example.com/%7B%7BMEDIA_URL%7D%7Dstyles.css.
I think it have something to do with STORE > Configuration > [GENERAL] Design > HTML Head > Miscellaneous Scripts.
Any help is appreciated, thank you.
Try running the Magento Minification tool in the admin panel. Then check your front end. Then if it works then turn off the minification tool as this will and should insert the correct URL inside the variable and all pages will have the new URL. Sounds loopy I know!
Khaleel - Thank you for your suggestion.
If I understand this correctly, you are talking about STORES > Configuration > Advanced > Developer > CSS Settings > Minify CSS Files set to YES. I did that, saved it, and it did not fix the issues. I did that back and forward, it does no changes. I also flushed the cache.
I not sure how helpful this is, but in "Magento 2 (with) sample data" /pub/media/styles.css contains styling for the sample data.
"Magento 2 (without) sample data" doesn't have styles.css file in that folder at all. And for testing purposes even if i put styles.css in to that folder, I still get this annoying 404 message.
So, my question is what is this file for and how it is being generated
href="{{MEDIA_URL}}styles.css"
Sorry it did not help. Strange one this. I have also updated to the latest M2 build and I am using (EE) and I am having issues with other plugins and customization. Sorry could not help
I saw this as well. I found it was due to the use of sample data without the sample data modules installed.
It is a poor implementation in the sample data to swap out the MEDIA_URL, and only works if the correct module is installed. As a quick fix, I added the ThemeSampleData module to my composer.json. (i.e. under require... "magento/module-theme-sample-data": "*")
@moderncodes,
as you have pointed out, in STORE > Configuration > [GENERAL] Design > HTML Head > Miscellaneous Scripts, there is
<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />
I've looked in the pub/media directory, and styles.css was there.
Although this is not an actual solution, I've bypassed the problem by editing the configuration to include correct css:
Just FYI, this problem occured to me on a Magento instance which was installed via composer. On my other instance installed via zip package, this error did not occur.
This issue still exists. Steps to reproduce:
$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mage2ee
$ bin/magento setup:install --backend-frontname=admin --db-host=localhost --db-name=m2_training --db-user=m2_training --db-password="algla904.-were-eioio0=" --base-url=http://example.dev/ --use-rewrites=1 --admin-user=admin --admin-password=password123 [email protected] --admin-firstname=Admin --admin-lastname=Admin --use-sample-data
Access the home page shows the sample data products without media.
So as @toddwolaver said, using the sample data without them being installed causes the issue.
Trying to fix this by running
$ bin/magento sampledata:deploy
$ bin/magento cache:flush
$ bin/magento setup:static-content:deploy
made no difference.
However, reinstalling (with the --cleanup-database
switch) worked. So basically an install with the sample data already installed.
Can't test right now, but I assume running bin/magento setup:upgrade
after bin/magento sampledata:deploy
would also have done the trick.
So to summarize, to get a fully working installation currently the following order of steps is required:
$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mage2ee
$ bin/magento sampledata:deploy
$ bin/magento setup:install --backend-frontname=admin --db-host=localhost --db-name=m2_training --db-user=m2_training --db-password="algla904.-were-eioio0=" --base-url=http://example.dev/ --use-rewrites=1 --admin-user=admin --admin-password=password123 [email protected] --admin-firstname=Admin --admin-lastname=Admin --use-sample-data
Or, to fix the issue on an existing installation, I assume the following works:
$ bin/magento sampledata:deploy
$ bin/magento setup:upgrade
Suggestion: maybe a notice that setup:upgrade
needs to be run should be added after sampledata:deploy
?
in my case i just need to enable module-theme-sample-data module, open file app/etc/config.php you add this line
'Magento_ThemeSampleData' => 1,
same problem after upgrading from 2.0.7 to 2.1 (EE), following @YugiHoang suggestion fixed it
maybe a real FIX is needed
Hi!
@Vinai Did you execute only this commands to reproducing?
$ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition mage2ee
$ bin/magento setup:install --backend-frontname=admin --db-host=localhost --db-name=m2_training --db-user=m2_training --db-password="algla904.-were-eioio0=" --base-url=http://example.dev/ --use-rewrites=1 --admin-user=admin --admin-password=password123 [email protected] --admin-firstname=Admin --admin-lastname=Admin --use-sample-data
Access the home page shows the sample data products without media.
How did you get sample products without installation of sample data packages?
What version of Magento were you using?
I reproduced it after I had set manually Magento_ThemeSampleData to 0.
Before it, I had installed Magento with Sample Data packages.
@BaDos Thanks for picking up the issue. I don't remember which version was current when I commented on the issue.
I think yes, those where the only two commands I had run. Right now, whenever I'm setting up a new project, I run bin/magento sampledata:deploy
and setup:upgrade
after the installation and it's fine.
For those troubleshooting this issue on Magento 2.1 and ahead, it appears that this field was relocated to CONTENT > Design > Configuration > Edit > HTML Head
, moved from its previous home under Store Configuration
Quickfix :
I ran into a similar issue, but different root cause. My page source was correctly rendering the {{MEDIA_URL}}
directive, but my pub/media/styles.css
file did not exist. I believe this happened because I ran setup:upgrade
at a point in time where pub/media
either didn't exist or wasn't writable. Running sampledata:deploy
and setup:upgrade
doesn't do anything at this point because the upgrade scripts have already run and won't run again. Even removing the sample data with sampledata:remove
did not seem to reset the state.
To fix this, I needed to run sampledata:reset
, then setup:upgrade
, then cache:flush
.
I confirmed that the setup:upgrade
command is what actually deploys the pub/media/styles.css
file into place by deleting the file and running the process again.
@ci2014 thank you for your report.
Please use the issue reporting guidelines to report an issue. Please, edit issue description and include the preconditions, the steps required to reproduce, the actual result, and the expected result.
Please, add the following information:
Solution is quite simple:
Comment the HTML line within the backoffice (CONTENT > Design > Configuration > Edit > HTML Head
):
<!--<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />-->
@ci2014 we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.
Preconditions
Steps to reproduce
Expected result
Actual result
GET http://192.168.0.55:8010/%7B%7BMEDIA_URL%7D%7Dstyles.css net::ERR_ABORTED (index):24
@gerrybarron using xampp?
If you using xampp then you may be facing this issue?it may happen for symbolic link
nope im not using xampp I installed it on our staging server. OS is ubuntu server 16.04
I have extra test magento 2.1.10 with sample data but it works fine. I dont know why it has an error on magento 2.1.8
have you done reindex. Maybe in design flat table's designs is not assigned?
yup did that too. but nothing changes
I have the same issue after php bin/magento setup:di:compile
. But php bin/magento setup:upgrade
fix it (in my case).
I just replaced
<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />
with
<link rel="stylesheet" type="text/css" media="all" href="http://mysite.com/pub/media/styles.css" />
In CONTENT > Design > Configuration > Edit > HTML Head
@Vinai Solution worked! Thank you.
Initially, I ran into this issue after performing a Flush Cache from magento backened.
Running bin/magento sampledata:deploy
and thenbin/magento setup:upgrade
fixed it.
Be aware, you need to setup your composer keys for this to work. Follow this link to learn more: http://devdocs.magento.com/guides/v2.0/install-gde/prereq/connect-auth.html
You'll have to find composer.json in your project root, Instructions on where to place these keys can be found here: (https://community.magento.com/t5/Magento-2-x-Version-Upgrades/Invalid-credentials-for-https-repo-magento-com-packages-json/td-p/22287/page/3)
I just replaced <link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}styles.css" />
in CONTENT > Design > Configuration > Edit > HTML Head
with nothing - saved it - put it back - working...
in my case i just need to enable module-theme-sample-data module, open file app/etc/config.php you add this line
'Magento_ThemeSampleData' => 1,
I wouldn't suggest this fix especially if you're installing with no sample data.
Setup version for module 'Magento_ThemeSampleData' is not specified
Try removing from global scope. It should work then.
@likemusic same here, bin/magento setup:upgrade solved the problem
Most helpful comment
I ran into a similar issue, but different root cause. My page source was correctly rendering the
{{MEDIA_URL}}
directive, but mypub/media/styles.css
file did not exist. I believe this happened because I ransetup:upgrade
at a point in time wherepub/media
either didn't exist or wasn't writable. Runningsampledata:deploy
andsetup:upgrade
doesn't do anything at this point because the upgrade scripts have already run and won't run again. Even removing the sample data withsampledata:remove
did not seem to reset the state.To fix this, I needed to run
sampledata:reset
, thensetup:upgrade
, thencache:flush
.I confirmed that the
setup:upgrade
command is what actually deploys thepub/media/styles.css
file into place by deleting the file and running the process again.