Angular 6 - 拒绝应用来自“..."的样式,因为它的 MIME 类型(“text/html")不是受支持的样式表 [英] Angular 6 - Refused to apply style from '...' because its MIME type ('text/html') is not a supported stylesheet
问题描述
当我在 index.html 中引用以下内容时,尝试升级到 Angular 6 并出现以下错误:
Trying to upgrade to Angular 6 and got the below error when I referred the below in index.html:
拒绝应用来自 'https://localhost:44394 的样式/~/assets/primengcss/themes/omega//theme.css' 因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查.
Refused to apply style from 'https://localhost:44394/~/assets/primengcss/themes/omega//theme.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
推荐答案
经过一番挖掘,找到了答案(至少对我有用):
Found the answer (at least worked for me), after some digging around:
看起来像在 Angular 6 中,我们需要将任何外部 CSS(如 bootstrap、fontawesome、Primeng 等)包含到 angular.json 中,如下所示:
Looks like inAngular 6 we need to include any external CSS (like bootstrap, fontawesome, Primeng etc.,) to the angular.json as below:
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/font-awesome/css/font-awesome.min.css",
"src/styles.css",
"./node_modules/primeng/resources/themes/omega/theme.css",
"./node_modules/primeng/resources/primeng.min.css",
"./node_modules/primeicons/primeicons.css"
],
"scripts": [
"./node_modules/jquery/dist/jquery.slim.min.js",
"./node_modules/popper.js/dist/umd/popper.min.js",
"./node_modules/bootstrap/dist/js/bootstrap.min.js"
]
这篇关于Angular 6 - 拒绝应用来自“..."的样式,因为它的 MIME 类型(“text/html")不是受支持的样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!