简体   繁体   English

App.js拒绝应用样式,拒绝执行脚本

[英]App.js refused to apply style, refused to execute script

I have read similar questions and the answers all revolved around correcting a line like this: 我读过类似的问题,答案都围绕着纠正这样的一行:

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

Unfortunately nothing I've read has fixed the issue. 不幸的是,我所读的没有任何东西可以解决这个问题。

In my index.html I have: 在我的index.html中,我有:

<link rel="stylesheet" href="public/css/style.css">
<script src="public/js/bundle.js"></script>

and in my app.js im using : 在我的app.js中,我使用:

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

When I visit the page the console logs 当我访问页面时,控制台日志

localhost/:1 Refused to apply style from ' http://localhost:3000/public/css/style.css ' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. localhost /:1拒绝应用' http:// localhost:3000 / public / css / style.css '中的样式,因为它的MIME类型('text / html')不是受支持的样式表MIME类型,并且严格的MIME检查是启用。

and

GET http://localhost:3000/public/js/bundle.js 404 (Not Found) GET http:// localhost:3000 / public / js / bundle.js 404(未找到)

localhost/:1 Refused to execute script from ' http://localhost:3000/public/js/bundle.js ' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. localhost /:1拒绝从' http:// localhost:3000 / public / js / bundle.js '执行脚本,因为其MIME类型('text / html')无法执行,并且启用了严格的MIME类型检查。

Adding a "/" at the end of public, like so: 在public末尾添加“ /”,如下所示:

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

and removing "public/" in: 并在以下位置删除“ public /”:

<script src="js/bundle.js"></script>
<link rel="stylesheet" href="css/style.css">

fixed the issue. 解决了这个问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM