这是我的index.html的代码:
<html>
<head>
<meta charset="UTF-8" >
<title>Index</title>
<link rel="stylesheet" href="styles/main.css" />
<link rel="stylesheet" ng-href="bower_components/bootstrap/dist/css/bootstrap.min.css" />
</head>
<body ng-app="app">
<div ng-view></div>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
<script src="scripts/angular/app.js"></script>
<script src="scripts/angular/controllers.js"></script>
</body>
</html>
但是返回时显示错误:
bootstrap.min.js:1 未捕获的语法错误:意外的标记 <
ui-bootstrap-tpls.min.js:1 未捕获的语法错误:意外的标记 <
是我代码的问题还是bootstrap的问题?当我添加时发现错误存在
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
和
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
进入
index.html
。有谁知道错误的原因?谢谢:)
肯定是bootstrap文件有问题。第 1 行包含 '<'.
尝试手动打开文件并将其删除。
我在 ASP.Net 上遇到了同样的问题。我所要做的就是清理解决方案并重建它。
Discord 讨论中的解决方案:使用 Bootstrap、Angular、React、Vue
出现此问题是因为
sirv public --single
决定为公共目录中不存在的任何路由/资源发送 index.html
- 路由问题。
当您请求(例如)图像并得到
200 text/html
响应而不是 404
时,您会立即知道遇到问题。
浏览器将尝试解析 index.html 内容,就好像它是图像(或在此错误的情况下是脚本)并吐出。更糟糕的是,缓存现在被该 URL 的垃圾数据污染,修复它的唯一方法是:
希望有帮助......我知道这让我发疯了一段时间!
这是因为文件地址不真实,请修改正确。根据我的地址:
correct <link rel="stylesheet" href="./css/bootstrap.rtl.min.css" />
wrong <link rel="stylesheet" href="/public/css/bootstrap.rtl.min.css" />
correct <script src="./js/bootstrap.bundle.min.js"></script>
wrong <script src="/public/bootstrap.bundle.min.js"></script>