Search code examples
node.jsfirebasefirebase-cli

firebase init error. (node:82729) UnhandledPromiseRejectionWarning


When I init firebase on my react app, I got the theme error after I passed some firebase asking.

under following on detail.

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.

I didn't have such a error when I used to create some react app. but,I got this error today.I think I will get this error on my node.js. but I don't know how I fix my node.js .

I am beginner for node.js and firebase. How should I fix this error?

I tried to fix some solution I found on Internet. following

I did reinstall node.js v12.18.3 from v10.12.3 .Also, I reinstall firebase-tools on my mac. I tried to reinstall firebase on my react app before firebase init.

Also, I ignored this error and then complete initializing firebase. but When I did firebase deploy , I couldn't do that .Instead of, I got this error on my command line.

Error: HTTP Error: 404, Method not found.

Now, I can't solve this error. If you have any ideas, please help and advise me. Thank you for reading!

06/ 09 / 2020 added my firebase.json and react package.json. here is 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"
      }
    ]
  }
}

here is 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"
    ]
  }
}

already installed packages.

firebase-tools@8.10.0

firebase@7.19.1

node.js v12.18.3

macOS10.15.6

bug picture enter image description here

and if I did firebase deploy I got this error. enter image description here

I tried to replace "$RESOURCE_DIR" with %RESOURCE_DIR% .I got different error. enter image description here


Solution

  • First update the firebase-tools:

    npm install -g  firebase-tools 
    

    After seeing your screenshot, I was able to see the error when deploying the function.

    Try to replace $RESOURCE_DIR with %RESOURCE_DIR% in your firebase.json file.

    Multi platform solution

    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"
    ]
    

    The previous was discussed in the following Github Issue. Please have a look at it.