IIS返回js文件的text / html,为什么?

问题描述 投票:0回答:1

当我的应用最初加载时一切正常,并且在Chrome中,控制台错误为0。当我按浏览器刷新时,收到以下错误:

拒绝执行脚本“ http://localhost:50001/dist/vendor-es5.js”,因为它的MIME类型('text / html')不可执行,并且严格的MIME类型检查是已启用。

我也收到'main-es5.js'的相同错误

错误是从我在这里的index.cshtml文件生成的:

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

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

更改

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

仍然给出相同的错误。

我的index.cshtml文件位于views / home中dist目录位于clientapp中

例如,如果我将脚本src上的引用更改为./clientapp/dist/vendor-es5.js,则该应用仍然会在第一次正确加载,但是当我按刷新时,不会出现任何控制台错误,但页面仍不刷新。任何人都有任何下一步的想法。

javascript iis mime-types
1个回答
0
投票

首先,请确保我们启用了以下HTTP功能,该功能使IIS可以正确处理对静态文件的请求。enter image description here它也可能与客户的构建工具(例如Webpack)的设置有关。Refused to execute script from because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled另外,在某些ReactJs应用程序中,使用App.use方法也可能是导致此类问题的原因。

© www.soinside.com 2019 - 2024. All rights reserved.