简体   繁体   中英

Angular 6 : Refused to execute script from 'URL' because its MIME type( ) is not executable, & strict MIME type checking is enabled

Getting following error while running .net Core Angular 6 SPA application:
The value for MIME type is blank:

在此处输入图像描述

Index.html File:

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>APP</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root>
    <div id="startup-message">
      <h1></h1>
      <p><span></span></p>
    </div>
  </app-root>
</body>
</html>

Package.JSON:

在此处输入图像描述

Customer Headers added in Web.Config file:

<customHeaders>
     <add name="Access-Control-Allow-Origin" value="*" />  
     <add name="Access-Control-Allow-Headers" value="Content-Type" />  
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />  
     <add name="X-Content-Type-Options" value="nosniff" />
  </customHeaders>

I could not reproduce your problem.You could create a new asp,net core and Angular template app to check whether the problem exists and compare the files.

It is likely that you have wrong url for the js files.

Besides, X-Content-Type option: nosniff tells the browser to force the MIME of the resource to be loaded.Try to comment out that.

Refer to Disable Chrome strict MIME type checking

Make sure you configure your static files BEFORE you configure your routes. In other words, something like this:

app.UseHttpsRedirection();

// nb: configure this first!!
app.UseStaticFiles();
if (!env.IsDevelopment())
{
    app.UseSpaStaticFiles();
}

app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
});

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
    spa.Options.StartupTimeout = new TimeSpan(0, 5, 0);

    if (env.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM