【问题标题】:firebase init error. (node:82729) UnhandledPromiseRejectionWarningfirebase 初始化错误。 (节点:82729)UnhandledPromiseRejectionWarning
【发布时间】:2020-12-24 16:29:32
【问题描述】:

当我在我的 react 应用上初始化 firebase 时, 在我通过一些火力基地询问后,我得到了主题错误。

下面详细介绍。

What language would you like to use to write Cloud Functions? (Use arrow keys)

❯ JavaScript
  TypeScript (node:82729) UnhandledPromiseRejectionWarning: Error
    at new FirebaseError (/usr/local/lib/node_modules/firebase-tools/lib/error.js:9:18)
    at module.exports (/usr/local/lib/node_modules/firebase-tools/lib/responseToError.js:38:12)
    at Request._callback (/usr/local/lib/node_modules/firebase-tools/lib/api.js:39:35)
    at Request.self.callback (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.EventEmitter.emit (domain.js:483:12)
    at Request.<anonymous> (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:315:20)
    at Request.EventEmitter.emit (domain.js:483:12)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/firebase-tools/node_modules/request/request.js:1083:12)
(node:82729) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:82729) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我以前创建一些 React 应用程序时没有出现这样的错误。但是,我今天收到了这个错误。我想我会在我的 node.js 上收到这个错误。但我不知道如何修复我的 node.js。

我是 node.js 和 firebase 的初学者。 我应该如何解决这个错误?

我尝试修复在 Internet 上找到的一些解决方案。关注

我确实从 v10.12.3 重新安装了 node.js v12.18.3。此外,我在我的 Mac 上重新安装了 firebase-tools。我试图在 firebase 初始化之前在我的 react 应用程序上重新安装 firebase。

另外,我忽略了这个错误,然后完成了 firebase 的初始化。但是当我执行 firebase deploy 时,我不能这样做。相反,我在命令行上收到了这个错误。

Error: HTTP Error: 404, Method not found.

现在,我无法解决此错误。 如果您有任何想法,请帮助和建议我。 感谢您的阅读!

06/ 09 / 2020 添加了我的 firebase.json 和 react package.json。 这是firebase.json

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
  },
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

这里是 package.json

{
  "name": "react-bot",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "firebase": "^7.19.1",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

已安装的软件包。

firebase-tools@8.10.0

firebase@7.19.1

node.js v12.18.3

macOS10.15.6

错误图片

如果我做了firebase deploy 我得到了这个错误。

我试图用 %RESOURCE_DIR% 替换 "$RESOURCE_DIR" 。我得到了不同的错误。

【问题讨论】:

  • 你能分享你的代码吗?当必须在处理拒绝的承诺上使用 .catch() 处理未处理的承诺拒绝时,通常会出现该错误。您能否将 firebase-tools 更新到最新版本并运行 firebase login --reauth ?请让我知道它是否有效。
  • 另外请分享您的 firebase.json 文件,以防前一个不起作用。
  • @NibrassH 感谢您的回复。一旦我删除了所有项目。 firest ,我确实为 firebase-tools@8.10.0 更新了 firebase-tools。然后我在我的反应应用程序上重新安装了 firebase@7.19.1。我做了firebase登录--reauth。但是,我得到了同样的错误......
  • @NibrassH 另外,我将 firebase.json 和 package.json 放在这里。请检查。如果您发现任何问题,请告诉我,我想解决这个问题。
  • 感谢您分享以上所有信息。我在下面添加了一个答案。

标签: node.js firebase firebase-cli


【解决方案1】:

首先更新firebase-tools:

npm install -g  firebase-tools 

看到你的截图后,我在部署函数时看到了错误。

尝试在firebase.json 文件中将 $RESOURCE_DIR 替换为 %RESOURCE_DIR%。

多平台解决方案

Linux

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

PowerShell

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

Cmd.exe

"predeploy": [
"npm --prefix %RESOURCE_DIR% run lint"
]

前面的讨论在下面的Github Issue。请看一下。

【讨论】:

  • 感谢您的回复!我试图在我的 firebase.json 中用 %RESOURCE_DIR% 替换 $RESOURCE_DIR。但我得到了一个不同的错误......请检查我的问题。我把我的错误图片。另外,我检查了你的 github 讨论。我是 Mac 用户(OS10.15.6)而不是 Windows。这个解决方案是一样的吗?
  • 这个错误是由firebase将我的开发环境识别为windows引起的吗?当我选择语言(Js 或 Ts)时,出现错误 "UnhandledPromiseRejectionWarning" 。这个错误也被firebase识别为windows?你怎么想 ?很抱歉继续提问。我期待您的回复。
  • 你能试试下面的代码吗? { "functions": { "predeploy": [ "npm --prefix \"%RESOURCE_DIR%\" run lint", "npm --prefix \"%RESOURCE_DIR%\" run build" ] } }
  • 您现在遇到的错误是因为您在 Mac 中,并且之前的语法可能不适用于 MAC。如果我之前的评论对您不起作用,您能否尝试以下评论:{ "functions": { "predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint", "npm --prefix \"$RESOURCE_DIR\" 运行构建" ] } }
  • 感谢您的回复!最后,我发现了这个错误的直接问题。这是我的 Firebase 版本。我的本地 firebase 版本(v6. ~ )比我的全球 firebase 版本旧。如果我升级 firebase 并在命令上执行 npm install -g firebase-tools ,我无法升级我的本地 firebase。因此,我删除了一次本地 firebase 并在本地 bin 上连接了 global pass。最后,一切正常!感谢您的建议,我解决了这个错误。如果我没有得到你的建议,我就找不到修复点。你是上帝!如果你来日本,我会给你寿司和天妇罗!!谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-09-15
  • 1970-01-01
  • 2018-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-29
相关资源
最近更新 更多