简体   繁体   English

拒绝应用来自“xxx/style.css”的样式,因为它的 MIME 类型(“text/html”)不是受支持的样式表 MIME 类型

[英]Refused to apply style from 'xxx/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type

I am new to Google App Engine and I'm trying to get the project I've been running locally hosted there.我是 Google App Engine 的新手,我正在尝试将我一直在本地运行的项目托管在那里。 My index.html shows up but it is not applying the CSS to it.我的 index.html 显示出来,但它没有应用 CSS。 I'm not exactly sure what a MIME type is, and I'm not exactly sure where in my code it's trying to get this from.我不确定 MIME 类型是什么,也不确定它试图从我的代码中的哪个位置获取它。 I just assumed that it would just load the tag that I have in my html and apply it like how it did while using browsersync.我只是假设它只会加载我在 html 中的标签,并像使用浏览器同步时那样应用它。 Index is loaded via:索引通过以下方式加载:

app.get('/', (req, res) => {
  res.sendFile(path.join(__dirname, '/index.html'));
});

CSS being loaded in index.html:在 index.html 中加载 CSS:

<link rel="stylesheet" type="text/css" href="style.css">

Permanant fix永久修复
server.js服务器.js

app.use(express.static('./public'));

and move all your static resources to public dir in your project then your html is valid Source并将所有静态资源移动到项目中的公共目录,然后您的 html 是有效的

When you're returning the stylesheet from the server, you should set the content-type attribute for the header to text/css ie you should have something like当您从服务器返回样式表时,您应该将标题的 content-type 属性设置为text/css即您应该有类似的内容

<link href="style.css" rel="stylesheet" />

app.get('/style', (req, res) => {
    res.setHeader('Content-Type', 'text/css');
    res.sendFile(path.join(__dirname, '/style.css'));
});

app.get('/', (req, res) => {
    res.setHeader('Content-Type', 'text/html');
    res.sendFile(path.join(__dirname, '/index.html'));
});


The issue could probably be with the CSS library starting with comments.问题可能出在以注释开头的CSS library上。

In development, if the stylesheet is started with some comments, it could be seen as something different from CSS.在开发中,如果样式表以一些注释开头,则可以将其视为与 CSS 不同的东西。

Removing the library and putting it into a vendor file, may solve the issue.删除库并将其放入供应商文件中,可能会解决问题。

Another possibility for Node.js applications is that you should check your configuration. Node.js应用程序的另一种可能性是您应该检查您的配置。

Example:例子:

app.use(express.static(__dirname + ‘/public’));

Notice that /public does not have a forward slash at the end, so you will need to include it in your href option of your HTML:请注意, /public 末尾没有正斜杠,因此您需要将其包含在 HTML 的 href 选项中:

Example:例子:

href=”/css/style.css”>

If you did include a forward slash /public/ , then you can just do href=”css/style.css”>.如果你确实包含了一个正斜杠/public/ ,那么你可以只做href=”css/style.css”>.

Be sure that CSS name is style.css without the second s at the end, that could also cause the issue.确保 CSS 名称是 style.css 末尾没有第二个 s,这也可能导致问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拒绝应用来自 'http://localhost:3000/css/style.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型 - Refused to apply style from 'http://localhost:3000/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用{filename}中的样式,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型 - Refused to apply style from {filename} because its MIME type ('text/html') is not a supported stylesheet MIME type Django:拒绝从...应用样式,因为它的 MIME 类型(&#39;text/html&#39;)不是受支持的样式表 MIME 类型 - Django: Refused to apply style from ... because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用“ <URL> &#39;,因为它的MIME类型(&#39;text / html&#39;)不是受支持的样式表MIME类型,并且启用了严格的MIME检查 - Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled 拒绝应用样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet MIME type 应用 css 样式时出现角度错误:拒绝从“路径”应用样式,因为其 MIME 类型(“文本/html”)不是受支持的样式表 MIME 类型 - Angular error when applying css style: Refused to apply style from 'path' because its MIME type ('text/html') is not a supported stylesheet MIME type 拒绝应用样式,因为它的 MIME 类型('text/html')不是受支持的样式表类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet type 拒绝应用来自 'http://localhost:2000/cssFile/style.css' 的样式,因为它的 MIME 类型('text/html') - Refused to apply style from 'http://localhost:2000/cssFile/style.css' because its MIME type ('text/html') 拒绝应用来自 'http://localhost:3000/assets/styles/signup.css' 的样式,因为它的 MIME 类型('text/html')不是受支持的样式表 MIME 类型 - Refused to apply style from 'http://localhost:3000/assets/styles/signup.css' because its MIME type('text/html')is not a supported stylesheet MIME type 拒绝从...应用样式,因为它的 MIME 类型 (&#39;text/html&#39;) 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查 - Refused to apply style from... because its MIME type ('text/html') is not a supported style-sheet MIME type, and strict MIME checking is enabled
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM