firebase show error when i try to run functions locally

Bhautik Chudasama

Showing the Firebase error whenever I run the function locally using emulator in CLI

$ firebase emulators:start --only functions

Starting emulators: ["functions"]

functions: Using node@8 from host.

functions: Emulator started at http://localhost:5001

functions: Watching "E:\dir\functions" for Cloud Functions...

Error: Cannot find module 'E:\dir\functions'

at Function.Module._resolveFilename (module.js:548:15)

at Function.Module._load (module.js:475:25)

at Module.require (module.js:597:17)

at require (internal/module.js:11:18)

at C:\Users\d\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:459:29

at Generator.next ()

at C:\Users\d\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71

at new Promise ()

at __awaiter (C:\Users\d\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:3:12)

at main (C:\Users\d\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:421:12)

Your function was killed because it raised an unhandled error.

I use typescript to write cloud functions.

here is my index.ts

import * as functions from 'firebase-functions';
import * as admin from "firebase-admin";

var cert = require("./skey.json");

admin.initializeApp({
    credential: admin.credential.cert(cert),
    databaseURL: "https://bhau-tk.firebaseio.com"
});

exports.basicHTTP = functions.https.onRequest((req, res) => {
    res.send("Hello world!!");
})

package.json contains

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "~7.0.0",
    "firebase-functions": "^2.3.0",
    "firebase-functions-test": "^0.1.6"
  },
  "devDependencies": {
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "private": true
}

and project structure is

enter image description here

Doug Stevenson

You should keep in mind that your project configuration is compiling TS sources files under src and putting the resulting JavaScript files in lib. So, you should refer to things in your functions folder relative to that location.

Since your compiled index.js is in lib, and your skey.json file is under src, you will have to refer to it that way:

var cert = require("../src/skey.json");

However, I wouldn't do it that way. I'd put skey.json in the functions folder (since it's not source code), and refer to it like this:

var cert = require("../skey.json");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unable to use ImageMagick when testing locally run Firebase functions

Run Firebase cloud functions locally?

Can I run Firebase Storage cloud functions locally?

when i try to run this cmd "npm run compile:sass" is show me this error

Error when I try to show a SnackBar in a builder

Error on jest when I try to run the test

Why is Google Cloud Functions throwing a "Invalid value for config firebase.databaseURL" error when I try to initialize a firebase app?

I try display snackbar with getx show error from firebase to user

Azure Functions - configuration settings returns null when I try to debug locally

I get an error when I try to show the comments for each post

React - Firebase module error when i try to import 'firebase/app'

Can't run the updated code when I run cloud functions emulators on locally

Lua: I get error when I try to run a script in Windows

I get an Error when I try to use Firebase Auth

PHP page does not load when I try to show an error message

Pygame window not responding error when i try to run a code

gettting this error when i try to run eclipse in ubuntu please help

error when i try to run app on emulator android studio

Error Twig when I try to run Symfony 3 project on server

Segmentation fault error when I try to run this program

When i try to run makemigrations command in django it gave me an error

Is there a way to get rid of the syntax error when I run try and except?

When I try to run the npm in the terminal, it showing the error

This Error will be shown when I'll try to run flutter project

Error occuring when I try to run decorator with @ - Python

When I try to use firebase in my flutter app it produces an error

How to run an Express API via Firebase Cloud Functions locally?

When I run the code chunks everything works but when I try to Knit I get an error

when i run my python code it continuously show syntax error