Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 尝试在本地运行函数时firebase显示错误_Node.js_Typescript_Firebase_Google Cloud Functions_Firebase Cli - Fatal编程技术网

Node.js 尝试在本地运行函数时firebase显示错误

Node.js 尝试在本地运行函数时firebase显示错误,node.js,typescript,firebase,google-cloud-functions,firebase-cli,Node.js,Typescript,Firebase,Google Cloud Functions,Firebase Cli,在CLI中使用emulator在本地运行函数时显示Firebase错误 $ firebase emulators:start --only functions 正在启动模拟器:[“函数”] 功能:使用node@8来自主持人 功能:Emulator在启动 功能:查看云功能的“E:\dir\functions” 错误:找不到模块“E:\dir\functions” 在Function.Module.\u解析文件名(Module.js:548:15) 在Function.Module.\u加载(Mo

在CLI中使用emulator在本地运行函数时显示Firebase错误

$ firebase emulators:start --only functions
正在启动模拟器:[“函数”]

功能:使用node@8来自主持人

功能:Emulator在启动

功能:查看云功能的“E:\dir\functions”

错误:找不到模块“E:\dir\functions”

在Function.Module.\u解析文件名(Module.js:548:15)

在Function.Module.\u加载(Module.js:475:25)

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

根据需要(内部/module.js:11:18)

位于C:\Users\d\AppData\Roaming\npm\node\u modules\firebase tools\lib\emulator\functionsEmulatorRuntime.js:459:29

在Generator.next()处

位于C:\Users\d\AppData\Roaming\npm\node\u modules\firebase tools\lib\emulator\functionsEmulatorRuntime.js:7:71

在新的承诺()

在等待者(C:\Users\d\AppData\Roaming\npm\node\u modules\firebase tools\lib\emulator\functionsEmulatorRuntime.js:3:12)

在main(C:\Users\d\AppData\Roaming\npm\node\u modules\firebase tools\lib\emulator\functionsEmulatorRuntime.js:421:12)

函数被终止,因为它引发了未处理的错误

我使用typescript编写云函数

这是我的索引。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包含

{
  "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
}
项目结构是


您应该记住,您的项目配置是在src下编译TS源文件,并将生成的JavaScript文件放入lib中。因此,您应该参考functions文件夹中相对于该位置的内容

由于编译的index.js位于lib中,而skey.json文件位于src下,因此您必须以这种方式引用它:

var cert = require("../src/skey.json");
然而,我不会那样做。我将skey.json放在functions文件夹中(因为它不是源代码),并像这样引用它:

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

你的项目布局是什么?skey.json在哪里,您是否正确引用了它?在src文件夹中!你能编辑这个问题来说明你的项目布局吗?谢谢!为了增加我的知识,这里有记录吗?我的失败带有“您的函数被终止”消息,但没有stacktrace等。