Firebase部署遇意外错误,本地测试正常,已更新依赖仍未解决
解决Firebase部署时出现"Error: An unexpected error has occurred."的问题
结合你遇到的情况和提供的调试日志,我给你几个实际可行的排查和解决办法:
1. 优先升级firebase-tools到最新版本
看你的调试日志,当前用的CLI版本是3.18.4,这是2018年的旧版本了,里面肯定存在不少已经修复的部署bug。赶紧执行下面的命令升级:
npm install -g firebase-tools@latest
升级完之后,最好重新登录一下Firebase账号,避免缓存的权限问题:
firebase logout firebase login
然后再尝试部署,大概率能解决这个莫名其妙的错误。
2. 确认项目ID完全正确
日志里显示你部署的项目ID是stashit-7885bob,去Firebase控制台核对一下,确保这个ID和你项目的实际ID完全一致,别出现拼写错误或者大小写问题(虽然Firebase项目ID是小写,但还是要确认)。
3. 清理functions的依赖缓存重新安装
有时候本地依赖的缓存会导致部署时的兼容性问题,你可以试试:
- 进入functions目录:
cd functions - 删除
node_modules文件夹和package-lock.json文件 - 重新安装依赖:
npm install
完成后回到项目根目录再执行部署命令试试。
4. 检查Google Cloud的API权限
虽然日志里说必要API已经启用,但有时候CLI的检测可能不准。你可以手动登录Google Cloud控制台,找到你的项目,确认Cloud Functions API和Runtime Config API确实是启用状态,同时确保你的账号拥有项目的部署权限(比如Editor以上的角色)。
你的问题背景
本地用firebase serve --only functions,hosting测试时一切正常,但执行firebase deploy或者指定部署functions和hosting时,却只弹出一句“Error: An unexpected error has occurred.”,没有更多详细提示。
之前已经按照官方提示更新了相关依赖:
npm install firebase-functions@latest --savenpm install firebase-admin@5.11.0 --savenpm install -g firebase-tools
而且也没有使用什么特殊的新特性。
调试输出(firebase deploy --debug)
[debug] [2018-05-14T18:59:35.734Z] ---------------------------------------------------------------------- [debug] [2018-05-14T18:59:35.739Z] Command: C:\Program Files\nodejs\node.exe C:\Users\Sushanth\AppData\Roaming\npm\node_modules\firebase-tools\bin\firebase deploy --only functions,hosting [debug] [2018-05-14T18:59:35.740Z] CLI Version: 3.18.4 [debug] [2018-05-14T18:59:35.740Z] Platform: win32 [debug] [2018-05-14T18:59:35.740Z] Node Version: v8.10.0 [debug] [2018-05-14T18:59:35.741Z] Time: Tue May 15 2018 00:29:35 GMT+0530 (India Standard Time) [debug] [2018-05-14T18:59:35.741Z] ---------------------------------------------------------------------- [debug] [debug] [2018-05-14T18:59:35.759Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"] [debug] [2018-05-14T18:59:35.762Z] > authorizing via signed-in user [debug] [2018-05-14T18:59:35.765Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"] [debug] [2018-05-14T18:59:35.766Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token { refresh_token: '1/V2t23LrBy9dznRfmTQnnh-0x3k3RrWFiA2EbNwRErOU', client_id: '563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com', client_secret: 'j9iVZfS8kkCEFUPaAeJV0sAi', grant_type: 'refresh_token', scope: 'email https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloudplatformprojects.readonly https://www.googleapis.com/auth/firebase openid' } Tue May 15 2018 00:29:35 GMT+0530 (India Standard Time) [debug] [2018-05-14T18:59:36.385Z] <<< HTTP RESPONSE 200 [debug] [2018-05-14T18:59:36.393Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/stashit-7885bob Tue May 15 2018 00:29:36 GMT+0530 (India Standard Time) [debug] [2018-05-14T18:59:37.606Z] <<< HTTP RESPONSE 200 [debug] [2018-05-14T18:59:37.607Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/stashit-7885bob/tokens Tue May 15 2018 00:29:37 GMT+0530 (India Standard Time) [debug] [2018-05-14T18:59:38.662Z] <<< HTTP RESPONSE 200 [info] [info] === Deploying to 'stashit-7885bob'... [info] [info] i deploying functions, hosting [debug] [2018-05-14T18:59:46.087Z] > [functions] package.json contents: { "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { "serve": "firebase serve --only functions", "shell": "firebase experimental:functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }, "dependencies": { "body-parser": "^1.18.2", "cookie-parser": "^1.4.3", "cors": "^2.8.4", "ejs": "^2.5.9", "express": "^4.16.3", "firebase": "^5.0.2", "firebase-admin": "^5.11.0", "firebase-functions": "^1.0.2" }, "private": true } [info] i functions: ensuring necessary APIs are enabled... [debug] [2018-05-14T18:59:46.087Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/cloudfunctions.googleapis.com/projectSettings/stashit-7885bob?view=CONSUMER_VIEW Tue May 15 2018 00:29:46 GMT+0530 (India Standard Time) [debug] [2018-05-14T18:59:46.092Z] >>> HTTP REQUEST GET https://servicemanagement.googleapis.com/v1/services/runtimeconfig.googleapis.com/projectSettings/stashit-7885bob?view=CONSUMER_VIEW Tue May 15 2018 00:29:46 GMT+0530 (India Standard Time) [debug] [2018-05-14T18:59:48.558Z] <<< HTTP RESPONSE 200 [debug] [2018-05-14T18:59:48.586Z] <<< HTTP RESPONSE 200 [info] + functions: all necessary APIs are enabled [debug] [2018-05-14T18:59:48.588Z] >>> HTTP REQUEST GET https://cloudresourcemanager.googleapis.com/v1/projects/stashit-7885bob
内容的提问来源于stack exchange,提问作者bobby.dreamer
相关产品推荐
相关产品推荐

