Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

后端 未结 7 1147
误落风尘
误落风尘 2020-12-17 16:25

I am trying to setup react routing which works when I click on something on my site the route works, however if I open a new tab and copy that url. I get

Ref         


        
相关标签:
7条回答
  • 2020-12-17 16:38

    Maybe you are pointing incorrectly

    <script src="utils.js"></script>        // NOT ok. Refused to execute script..MIME
    
    <script src="js/utils.js"></script>    // OK
    
    0 讨论(0)
  • 2020-12-17 16:38

    In my case, I encountered this issue because the build process did not actually build the JavaScript bundle.

    The build just emitted a warning instead of an error(!), and so this issue was only found when the build was pushed to a staged deployment environment.

    Hence to fix this issue I fixed the problem with the bundle not being built.

    0 讨论(0)
  • 2020-12-17 16:40

    I recently had to add the following to the headers as part of a security audit resolution

    X-Content-Type-Options: nosniff
    

    After that i started getting these errors. I am yet to figure out a permanent solution for this. The pages seems to be working though. The noise in the console is just annoying!

    0 讨论(0)
  • 2020-12-17 16:42

    I got the same exact error and find out that I need to change my script in

    index.html

    from

      <script src="App.js"></script>
    

    to

      <script src="/App.js"></script>
    

    so if you have a "." or nothing in front of your file, just replace it with "/". I hope this helps you or someone else.

    0 讨论(0)
  • 2020-12-17 16:47

    Another thing that can cause this is if the contentBase property is not set correctly. This came up for us in that we were requesting a JS file but getting a 404 and the 404 "page" served by webpack-dev-server comes back as text/html.

    0 讨论(0)
  • 2020-12-17 16:49

    Just edit webpack config by editing this:

        devServer: {
                     historyApiFallback: true
                   }
    

    And also add this to public/index.html:

         <base href="/" />
    

    This should do the trick..

    0 讨论(0)
提交回复
热议问题