angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Open mohibrahimm opened this issue 8 years ago • 48 comments

This is the issue I'm getting

Angular CLI: 1.7.2 Node: 8.9.4 OS: win32 x64 Angular: 5.2.5 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

@angular/cli: 1.7.2 @angular-devkit/build-optimizer: 0.3.2 @angular-devkit/core: 0.3.2 @angular-devkit/schematics: 0.3.2 @ngtools/json-schema: 1.2.0 @ngtools/webpack: 1.10.1 @schematics/angular: 0.3.2 @schematics/package-update: 0.3.2 typescript: 2.5.3 webpack: 3.11.0

Deploy files to to server Service Worker caches all the files Deploy updated files to server Get this error on refresh after deploying updated files: Refused to execute script from Refused to apply style from 'https://martmax.co/martmax/styles.90e231a43b112dde0a8e.bundle.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. Refused to execute script from 'https://martmax.co/martmax/inline.42eab311bb328d4389bc.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. martmax.co/:1 Refused to execute script from 'https://martmax.co/martmax/polyfills.a6e3c1aba633d4169f73.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. martmax.co/:1 Refused to execute script from 'https://martmax.co/martmax/scripts.a5ebe8c46eb086e27504.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. martmax.co/:1 Refused to execute script from 'https://martmax.co/martmax/main.dd14f2660d7784d60e49.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. martmax.co/:1 Refused to apply style from 'https://martmax.co/martmax/styles.90e231a43b112dde0a8e.bundle.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Doing a hard refresh (CMD + SHIFT + R) skips the service worker cache and loads the newly deployed files without any issues. And then doing a regular refresh causes the error to come back.

My sw.js is not being cached and have nginx setup.

Deploying an update and refreshing pulls files from service worker, but they have the incorrect content- image image

image

My initial guess is that it's an issue with index.html , but asking if you guys have any other guesses.

@comewalk @jesperronn @mprobst @filipesilva @Brocco @texel

mohibrahimm avatar Apr 13 '18 16:04 mohibrahimm

Same issue. Any luck?

anupamarachuri avatar Apr 18 '18 17:04 anupamarachuri

So, I don't know if this is the same issue that you guys are having, but I am working with an ejected project and, in my efforts, I noticed that, in the webpack.config.development.js file, the BaseHrefWebpackPlugin was being called with an empty parameters object:

    new BaseHrefWebpackPlugin({}),

So I changed it to:

    new BaseHrefWebpackPlugin({baseHref: baseHref}),

And set the constant declared at the beginning of the file to:

const baseHref = "/";

And it started working flawlessly. Again, no idea if that is what is going on for you, as I see you are working on an un-ejected project, but hopefully it helps somehow!

s73obrien avatar Apr 18 '18 20:04 s73obrien

I have the same issue with loading a js file in a script tag from the assets folder.

TimMeissner avatar May 16 '18 08:05 TimMeissner

@TimMeissner I had the same issue (js file in script tag from assets folder) where the script tag was being dynamically generated, and was using 'text/javascript' as the type. Changing it to 'application/javascript' fixed it.

ergwun avatar May 17 '18 07:05 ergwun

Same here, blocks us from upgrading to Angular 6. Changing the script type didnt solve the issue for me.

gs00s avatar May 17 '18 15:05 gs00s

If you are a .NET Core developer, you should set the content-types manually, because their default value is null or empty:

var provider = new FileExtensionContentTypeProvider();
app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = provider // this is not set by default
});

For other web servers you should do the same by setting the correct content-types.

VahidN avatar May 19 '18 14:05 VahidN

@VahidN I dont understand, where should I put this code? Angular CLI serves the files in my case.

gs00s avatar May 19 '18 19:05 gs00s

Angular CLI uses webpack-dev-server. I think they should make it configurable to set mimeTypes

mime: {
      'application/javascript': ['js'],
      'text/css': ['css'],
   }

VahidN avatar May 21 '18 03:05 VahidN

It worked with previous versions and if I use plain WebpackDevServer it serves files without issues.

gs00s avatar May 21 '18 06:05 gs00s

This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?

You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.

filipesilva avatar May 21 '18 11:05 filipesilva

While trying to reproduce the issue, it is caused by breaking changes in the names of the bundled files.

The files lost their bundle suffix and inline became runtime. The bad part is that I haven't found any mentions about these changes.

The generated files are now:

  • inline.bundle.js => runtime.js
  • polyfills.bundle.js => polyfills.js
  • vendor.bundle.js => vendor.js
  • main.bundle.js => main.js

Non existing files return status code 404 in text response and this is why Chrome throws these errors mentioned in the ticket title.

gs00s avatar May 22 '18 10:05 gs00s

@blacksonic we have changed the bundle names, yes. But also changed our build pipeline to use the updated names.

Do you have a custom index file from which you load the bundles manually?

filipesilva avatar May 22 '18 11:05 filipesilva

Yes, we have a different service that uses these files.

gs00s avatar May 22 '18 13:05 gs00s

In my case I just forgot that I had a base href in my index.html. Just posting in case anyone is as forgetful as I, because that is what brought me here.

steffen678 avatar May 29 '18 14:05 steffen678

What do you mean by base href @veluria ? Do we need to remove <base href="/"> from index.html? It was there almost from the beginning. Thx.

attilacsanyi avatar May 29 '18 14:05 attilacsanyi

@attilacsanyi I had a different one (<base href="/app">) and that was what caused this error for me when using ng serve! :)

steffen678 avatar May 29 '18 14:05 steffen678

I try using this option --output-hashing none and it seems to do the work (for now..). You can add it to your ng build --prod command

dgsqrs avatar Jun 01 '18 20:06 dgsqrs

I have the exact same problem like the author of this issue. I have an Angular application that runs on several nodes and on some of them I get this error in the developer console: Refused to execute script from 'https://www.my-domain.com/virtualdirectory/main.cbffc8c33220549d9ac8.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I haven't found a fix for it...

Shamshiel avatar Jun 04 '18 08:06 Shamshiel

Similar to a few of the above, disabling cache in the network tab of chrome dev tools allowed me to load the page, but it is not a fair expectation for users. This behavior came after upgrading to 6, and my project is not ejected and is not using service workers. With any new version deployed it happens, so my suspect is the output hashing because it will render index.html but it seems to not know how to use any formerly named .bundle the browser cached.

b-johnse avatar Jun 06 '18 20:06 b-johnse

So as I look more at it, the index.html seems cached and is asking for the old hashes, which the server returns a 404 because they no longer exist, and it tries to apply the error response which gives the above error in console (my console errors are identical, not quite all the same bundles though).

b-johnse avatar Jun 08 '18 15:06 b-johnse