简体   繁体   English

拒绝应用{filename}中的样式,因为它的MIME类型('text / html')不是受支持的样式表MIME类型

[英]Refused to apply style from {filename} because its MIME type ('text/html') is not a supported stylesheet MIME type

I have an index.ejs file that I am using with Express for a localhost web server and I am getting 4 errors of 2 types: Errors Here is my code: 我有一个与Express一起用于本地主机Web服务器的index.ejs文件,并且遇到2种类型的4个错误: 错误这是我的代码:

<html>
<head>
    <title>Home</title>
    <!-- <link rel="stylesheet" type="text/css" href="styles/main.css"> -->
    <link rel="stylesheet" type="text/css" href="styles/mobile.css">
    <link rel="icon" href="public/styles/images/icon.png">
</head>
<style type="text/css">
@import url("styles/main.css");
</style>
<body>
    <nav>

    </nav>
    <main>

    </main>
    <footer>

    </footer>
    <script type="text/javascript" src="scripts/javascript/main.js"></script>
    <script type="text/javascript" src="scripts/javascript/mobile.js"></script>
</body>

I tried making test CSS and JavaScript files in the same directory as the index.ejs file but I got errors for those as well. 我尝试在与index.ejs文件相同的目录中制作测试CSS和JavaScript文件,但这些文件也出现错误。 When I change the file type to index.html, there are no errors which was interesting. 当我将文件类型更改为index.html时,没有任何有趣的错误。 If someone could tell me why that is that would help a lot. 如果有人可以告诉我原因,那将会很有帮助。 Thanks! 谢谢!

I've never seen the @import url("styles/main.css"); 我从未见过@import url("styles/main.css"); method, so I can't say it won't work. 方法,所以我不能说它不起作用。

Typically you get that error when you have an error in your css/js path, or your didn't properly configure your public folder on your app.js . 通常你得到这个错误,当你在你的CSS / JS路径有一个错误,或者你没有正确地配置您的public对你的文件夹app.js

Make sure you have app.use(express.static('public')); 确保您具有app.use(express.static('public')); , and that you have a folder called public , which has the following folders: css , js , images . ,并且您有一个名为public的文件夹,其中包含以下文件夹: cssjsimages Put all of your js/css/images in these folders. 将所有js / css / images放在这些文件夹中。

Then on your index.ejs change the following: 然后在您的index.ejs更改以下内容:

//to reference a css file:
<link rel="stylesheet" src="/css/yourFile.css">

//to reference a js file:
<script href="/js/yourFile.js"></script>

//to reference an image:
<link rel="icon" src="/images/yourImage.png">

暂无
暂无

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

相关问题 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 拒绝应用来自“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 拒绝应用样式,因为它的 MIME 类型('text/html')不是受支持的样式表类型 - Refused to apply style because its MIME type ('text/html') is not a supported stylesheet 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 拒绝应用来自 '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 拒绝应用来自 '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 拒绝应用来自 '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')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM