[英]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
的文件夹,其中包含以下文件夹: css
, js
, images
。 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.