首页 > 解决方案 > firebase 初始化错误。(节点:82729)UnhandledPromiseRejectionWarning

问题描述

当我在我的 react 应用程序上初始化 firebase 时,在我通过了一些 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.

当我用来创建一些反应应用程序时,我没有遇到这样的错误。但是,我今天收到了这个错误。我想我会在我的 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.

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

2020 年 6 月 9 日添加了我的 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" 。我得到了不同的错误。 在此处输入图像描述

标签: node.jsfirebasefirebase-cli

解决方案


首先更新firebase-tools:

npm install -g  firebase-tools 

看到您的屏幕截图后,我能够在部署该功能时看到错误。

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

多平台解决方案

Linux

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

电源外壳

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

命令文件

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

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


推荐阅读