服务firebase错误=>功能:模拟器错误。错误解析触发器:找不到模块“控制器/数据控制器”

时间:2019-05-05 15:53:48

标签: typescript firebase express

我正在使用Firebase,使用打字稿表达,并且使用 firebase serve --only hosting,functions 报错。

我的代码是下一个:

*在 src 内部,我有一个名为 controllers 的目录,在 data-controller.ts 文件中,具有以下代码:

 export class DataController {
     public router: Router
     public cultura = "";
     public coleccio = "";            
     public esProduccio:string = "";


     constructor() {
       this.router = Router();
       this.init();
     }

     public static GetController(): Router {
       var router: Router;

       router.get('/:cultura/:coleccio/:esProduccio',  (req, resp) => {
           let cultura = req.params.cultura;
           let coleccio = req.params.coleccio;
           let esProduccio = req.params.esProduccio;

           let dal = new DAL_Base(esProduccio);

           dal.Get(cultura, coleccio).then(function (res) {
             resp.send(JSON.stringify(res)); 
           }).catch(function (error)
           {
             console.log(error);
             resp.send(error)
           });
         });

       return router;
     }

     init() {      
       this.router.get('/:cultura/:coleccio/:esProduccio',  (req, resp) => {
         let cultura = req.params.cultura;
         let coleccio = req.params.coleccio;
         let esProduccio = req.params.esProduccio;

         let dal = new DAL_Base(esProduccio);

         dal.Get(cultura, coleccio).then(function (res) {
           resp.send(JSON.stringify(res)); 
         }).catch(function (error)
         {
           console.log(error);
           resp.send(error)
         });
       });
     } }

我的主要代码 app.ts 是:

import { DataController } from "controllers/data-controller";


const functions = require("firebase-functions");
const express = require("express");

export class App {
        constructor () {

        }

        funcion(): void {
                var data: DataController = new DataController();
        }
}

const app = new App();
exports.app = functions.https.onRequest(app);

我的 firebase.json 是:

{
  "hosting": {
    "public": "public",
    "rewrites": [{
      "source": "**",
      "function": "app"
    },{
      "source": "**",
      "function": "DataController"
    }]
  },
  "functions": {
    "predeploy": "npm --prefix functions run build"
  }
}

我的 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"
  },
  "main": "dist/app.js",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.16.4",
    "firebase-admin": "~7.0.0",
    "@types/debug": "0.0.31",
    "@types/express": "^4.16.0",
    "@types/express-serve-static-core": "^4.16.0",
    "babel-polyfill": "^6.26.0",
    "body-parser": "^1.18.3",
    "cjs": "0.0.11",
    "commonjs": "0.0.1",
    "debug": "^4.1.0",
    "grunt-cli": "^1.3.2",
    "gulp-typescript": "^5.0.0-alpha.3",
    "http": "0.0.0",
    "jade": "^1.11.0",
    "mongodb": "^3.1.10",
    "mongoose": "^5.4.1",
    "morgan": "^1.7.0",
    "request": "^2.88.0",
    "systemjs": "^2.1.1",
    "ts-node": "^7.0.1",
    "typings": "^2.1.1"
  },
  "devDependencies": {
    "@types/body-parser": "0.0.33",
    "@types/cors": "^2.8.4",
    "@types/mongoose": "^5.3.6",
    "@types/morgan": "^1.7.32",
    "babel-preset-es2015": "^6.24.1",
    "express-serve-static-core": "^0.1.1",
    "firebase-functions": "^2.3.0",
    "grunt": "^1.0.3",
    "grunt-contrib-jshint": "^2.0.0",
    "grunt-contrib-watch": "^1.1.0",
    "grunt-ts": "^6.0.0-beta.21",
    "grunt-tslint": "^5.0.2",
    "gulp-babel": "^8.0.0",
    "linq-es2015": "^2.4.33",
    "ts-lint": "^4.5.1",
    "ts-loader": "^5.4.5",
    "tslint": "^5.12.0",
    "typescript": "^3.2.2",
    "webpack-node-externals": "^1.7.2"
  },
  "private": true
}

tsconfig.json 是:

{   “ compilerOptions”:{     “ module”:“ commonjs”,     “ moduleResolution”:“节点”,     “漂亮”:是的,     “ sourceMap”:是的,     “ target”:“ es2015”,     “ lib”:[“ dom”,“ esnext”],     “ outDir”:“ ./dist”,     “ baseUrl”:“ ./src”,     “ alwaysStrict”:是   },   “ include”:[“ src / ** / *。ts”],   “排除”:[“ node_modules”] }


我收到此错误:

i  functions: Preparing to emulate functions.
i  hosting: Serving hosting files from: public
+  hosting: Local server: http://localhost:5000
Warning: You're using Node.js v10.13.0 but the Google Cloud Functions runtime is only available in Node.js 6 (Deprecated), Node.js 8, and Node.js 10 (Beta). Therefore, results from running emulated functions may not match production behavior.
!  functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
!  functions: Error from emulator. Error parsing triggers: Cannot find module 'controllers/data-controller'

Try running "npm install" in your functions directory before deploying.

我该如何解决?

当我不声明DataController没有失败时。我测试过要在构造函数中声明它,而两个都不声明。

Thx

0 个答案:

没有答案