1

When my app initially loads all is ok and in Chrome, console errors are 0. When I press the browser refresh, I receive the following error:

Refused to execute script from 'http://localhost:50001/dist/vendor-es5.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I also receive the same error for 'main-es5.js'

The error is generated from my index.cshtml file in here I have:

@section scripts {
    <script src="~/dist/vendor-es5.js" asp-append-version="true"></script>

    <script src="~/dist/main-es5.js" asp-append-version="true"></script>
}

changing the

<script type="text/javascript" src="~/dist/vendor-es5.js" asp-append-version="true"></script>

still gives the same error.

my index.cshtml file resides in views/home the dist directory resides in clientapp

if I change the reference on the script src to be ./clientapp/dist/vendor-es5.js for instance, then the app still loads correctly first time in, but then when I press the refresh, I get no console errors, but the page still doesn't refresh. Anybody have any ideas where I should go next.

Liam
  • 27,717
  • 28
  • 128
  • 190
bilpor
  • 3,467
  • 6
  • 32
  • 77
  • 1
    seems like the webserver return incorrect MIME type for the `~/dist/vendor-es5.js` – IAfanasov May 22 '20 at 09:36
  • @IAfanasov looking at the mime types in iis .js files are set to application/javascript – bilpor May 22 '20 at 10:06
  • This is nothing to do with angular. This is a server side issue. You need to get your web server to return the correct mime type – Liam May 22 '20 at 10:33
  • 1
    This appears to have nothing to do with C# specifically. More likely an IIS issue. – ADyson May 22 '20 at 10:33
  • @Liam though if it was an IIS issue, on the basis the mime type for .js file is set to 'application/javascript', then I'd expect to see this in the error as opposed to 'text/html' – bilpor May 22 '20 at 10:49
  • Well what is the mime type in the network tab of chrome? That tells you what HTTP is being sent from IIS. If it's wrong there (which I'm pretty sure it will be) then it's a problem with IIS (or proxy or some other network device) – Liam May 22 '20 at 10:51
  • @Liam from the network tab in chrome for both files the type is script – bilpor May 22 '20 at 10:53
  • That doesn't make any sense. We're going to need to see a [mcve]. My only other guess is some kind of chrome extension. Disable all extension and see if it goes away – Liam May 22 '20 at 10:58
  • 1
    Wait; `script`? That's not a [valid mime type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) – Liam May 22 '20 at 11:00
  • @bilpor can you check IIS settings is `Static content` enabled? https://stackoverflow.com/a/42191613/943792 – Radik May 22 '20 at 11:27

1 Answers1

0

First, please ensure that we have enabled the below HTTP feature, which makes IIS can properly process requests for static files.
enter image description here
It may also have something to do with the setup of your client’s build tool, for example Webpack.
Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled
In addition, in certain ReactJs applications, the usage of App.use method also might be a reason for this type of issue.

app.use(express.static(__dirname + "/static"));

Please refer to the below links.
loading a bundle.js file from webpack changes mime type to text/html
Refused to execute script from because its MIME type (...) and strict MIME type (...)
Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled Refused to execute script, strict MIME type checking is enabled?

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22