mms*_*arz 7 syntax-error firebase reactjs firebase-hosting
我试图在 Firebase 上部署我的 react SPA,但只有空白页面出现这样的控制台错误: “Uncaught SyntaxError: Unexpected token <”
为了排除第三方库,我创建了新的 React-app 来部署。并得到了完全相同的问题。
终端日志:
有人知道如何解决这个问题吗?
链接到 Firebase 部署的 create-react-app 起始页
来自 firebase.json 的代码
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": [
{
"source" : "*",
"destination" : "/index.html"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
您的 main.js 再次包含页面 html 数据。
<!doctype html><html lang="en"><head>...
.
当浏览器加载 JS 文件并尝试解释它时,它失败了,因为 HTML 显然不是 javascript。它试图用“哦,我找到了一个 < 但这不是我所期望的”来传达它的困惑。
您似乎已经为您的服务器配置了默认路由,并且每个请求都返回您的 index.html。
我在你的一张屏幕截图中注意到,你对“将所有 url 重写为 index.html ”说“是”——它正是这样做的。您不应该激活它,因为您的所有请求将始终返回index.html
.
请查看您的firebase.json
文件。您将在那里找到托管和路由的说明。
API 文档在这里:
https://firebase.google.com/docs/hosting/full-config
您可能想要特别查看重定向数组,如下所示:
"redirects": [
{
"source" : "*",
"destination" : "/index.html"
}
]
Run Code Online (Sandbox Code Playgroud)
在这里,您告诉服务器将所有流量重定向到/index.html
. 删除重定向条目,重新部署,一切都会好起来的。
所以这个重定向部分很可能会解决这个问题:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"redirects": []
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4402 次 |
最近记录: |