gpt4 book ai didi

reactjs - Firebase 部署成功后出现空白页

转载 作者:行者123 更新时间:2023-12-03 13:15:13 25 4
gpt4 key购买 nike

当我使用 npm start 命令时,我的 ReactJs 应用程序在本地机器上运行良好。但是,当我尝试使用 firebase init 将应用程序部署到 Firebase 时,我看到一个空白页面。我可能做错了什么?

更新:我必须编辑 Firebase.json 文件才能删除

"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run lint"],

line,因为我收到了与此相关的错误。

Firebase.json:

{
"database": {
"rules": "database.rules.json"
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"source": "functions"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}

Firebase 部署命令输出:

=== Deploying to 'socialmedia-5ec0a'...

i deploying database, storage, firestore, functions, hosting
i database: checking rules syntax...
+ database: rules syntax for database socialmedia-5ec0a is valid
i storage: checking storage.rules for compilation errors...
+ storage: rules file storage.rules compiled successfully
i firestore: checking firestore.rules for compilation errors...
+ firestore: rules file firestore.rules compiled successfully
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i storage: uploading rules storage.rules...
i firestore: uploading rules firestore.rules...
i functions: preparing functions directory for uploading...
i hosting[socialmedia-5ec0a]: beginning deploy...
i hosting[socialmedia-5ec0a]: found 5 files in public
+ hosting[socialmedia-5ec0a]: file upload complete
i database: releasing rules...
+ database: rules for database socialmedia-5ec0a released successfully
+ storage: released rules storage.rules to firebase.storage/socialmedia-5ec0a.appspot.com
+ firestore: released rules firestore.rules to cloud.firestore
i hosting[socialmedia-5ec0a]: finalizing version...
+ hosting[socialmedia-5ec0a]: version finalized
i hosting[socialmedia-5ec0a]: releasing new version...
+ hosting[socialmedia-5ec0a]: release complete

+ Deploy complete!

Project Console: https://console.firebase.google.com/project/socialmedia-5ec0a/overview
Hosting URL: https://socialmedia-5ec0a.firebaseapp.com

Chrome F12 输出: enter image description here

最佳答案

我也遇到了同样的问题。 http://localhost:3000/为应用程序提供了良好的服务,但是当我使用 npm run build 进行部署,然后使用 firebase deploy 时,我只看到一个空白页面。

我不确定原因,但我将 firebase.json 中的“public”属性更改为“build”并且它起作用了。

这是我的新 firebase.json 文档。

{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}

关于reactjs - Firebase 部署成功后出现空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52177222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com