I encountered an issue while using Typescript to write some Firebase cloud functions. Here is a snippet of my code:
index.ts
export * from "./Module1";
Module1.ts
import * as functions from "firebase-functions";
export const test = functions.https.onRequest(
(request, response) => {
console.log("Hello");
}
);
After deploying the code using firebase deploy
, I noticed that the compiled Module1.js file in the lib
directory did not contain the console.log()
line:
Module1.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const functions = require("firebase-functions");
exports.test = functions.https.onRequest((request, response) => {
}
When I checked the firebase console, there was no log output for the line console.log("Hello");
. I suspect that tsc
may have removed the console.log()
statement during compilation, but I'm not sure why. Here's a snippet of my tsconfig.json:
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2015",
"resolveJsonModule": true,
"esModuleInterop": true
},
"compileOnSave": true,
"include": ["src"]
}
If anyone has insights or solutions to this issue, I would greatly appreciate your help.