2

I have an error in magento 2.2 frontend and backend. Scripts and stylesheets fail to load, the console states that the MIME type is incorrect and require.js can't be loaded. Problem still occurs after deploying new static content, removing cache folders, cleaning and flushing the cache and re-indexing.

1

Update 2:

First of all I am able to recreate this issue when <magento>/pub/static/.htaccess is deleted or missing. It is very easy to accidentally delete this file, so check this first! Download a fresh copy from github if necessary. That link is for version 2.2.4, it may differ for other versions.

Note running the command rm -rf pub/static/* will delete all files in pub static EXCEPT .htaccess. I made the mistake early on of running the command with just pub/static/, which deletes the entire folder.

And now my original answer which still applies:

Sort of a hunch here, but I get similar issues when I forget to add this code to my <VirtualHost> block in my apache configuration.

<Directory "/Users/jamil/www/mymagento2site.com">
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

AllowOverride All might be the important piece here, I find this isn't the default on most of my set ups. Without it, .htaccess files get ignored.

Whole VHost setup would look something like this:

<VirtualHost *:80>
  DocumentRoot "/Users/jamil/www/mymagento2site.com"
  ServerName mymagento2site.com
  ServerAlias www.mymagento2site.com
  <Directory "/Users/jamil/www/mymagento2site.com">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>
</VirtualHost>

Another question has an answer saying to make sure you have the correct .htaccess file in your pub/static/ folder. This can sometimes get deleted if you do rm -rf pub/static in the command line, instead of the correct command: rm -rf pub/static/*.

Update

First of all if you're using a custom theme I would eliminate that variable and change to luma.

Regardless, the issue sounds like it's server side. I'm not an expert in apache but I've referenced my local setup and did a bit of research and found you can add mime types in a few different ways. Let me add that I'm a bit worried that this represents a larger issue with your setup.

In my apache configuration I have this declaration:

LoadModule mime_module modules/mod_mime.so

# ...

<IfModule mime_module>
  #
  # TypesConfig points to the file containing the list of mappings from
  # filename extension to MIME-type.
  #
  TypesConfig /Applications/MAMP/conf/apache/mime.types
</IfModule>

Without that, I get an error:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://localhost/test/style.css".

The TypesConfig links to the file mime.types, a copy of which can be found at the link.

You can also define mime types one at a time in your .htaccess like so:

AddType text/css css

In order for that to work, my note above is still true, you need the AllowOverride directive to be defined as All. I think this is probably already enabled. If not you would be seeing other issues, like a 404 when trying to accessing admin.

I assumed you were using VirutalHosts, but if you're not then you can add AllowOverride All in your apache configuration like so:

<Directory "/">
  AllowOverride All
</Directory>

Note, most or all of the changes above require you to restart apache.

Hope this helps!

  • hi, i don't have virtual hosts in apache. I tried to change the .htacces file but it i still have that issue. The error is that one Refused to apply style from '127.0.0.1:8888/version1521537203/frontend/Test/magento/it_IT/…' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. – user48824 Mar 20 '18 at 9:26
  • Added some more info. Sounds like your apache config is incomplete. Did you install using WAMP, XAMP, MAMP, etc? – jamil Mar 20 '18 at 17:11
  • I use Mamp php 7.0.8 and i installed again magento i did really not know what to do :D – user48824 Mar 20 '18 at 17:23
  • Did it work after reinstall? – jamil Mar 20 '18 at 17:26
  • It was a cleaner installation so yeah – user48824 Mar 20 '18 at 17:52

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.