During firebase deploy
in terminal, I get an error on this line:
// index.js in the output folder
const firebase_functions_1 = __importDefault(require("firebase-functions"));
exports.buyUsedServer = firebase_functions_1.default.https.onRequest(express);
// index.ts in the source folder
import firebaseFunctions from 'firebase-functions';
export const buyUsedServer = firebaseFunctions.https.onRequest(express);
//# sourceMappingURL=index.js.map
What is firebaseFunctions (or the default object) causing an issue here?
This is the full stack trace:
i functions: preparing functions directory for uploading...
Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'https' of undefined
at Object.<anonymous> (/home/owner/PhpstormProjects/shopify/project/functions/outDir/index.js:170:54)
at Module._pile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:681:19)
at require (internal/modules/cjs/helpers.js:16:16)
at /home/owner/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
at Object.<anonymous> (/home/owner/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/triggerParser.js:53:3)
at Module._pile (internal/modules/cjs/loader.js:774:30)
During firebase deploy
in terminal, I get an error on this line:
// index.js in the output folder
const firebase_functions_1 = __importDefault(require("firebase-functions"));
exports.buyUsedServer = firebase_functions_1.default.https.onRequest(express);
// index.ts in the source folder
import firebaseFunctions from 'firebase-functions';
export const buyUsedServer = firebaseFunctions.https.onRequest(express);
//# sourceMappingURL=index.js.map
What is firebaseFunctions (or the default object) causing an issue here?
This is the full stack trace:
i functions: preparing functions directory for uploading...
Error: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'https' of undefined
at Object.<anonymous> (/home/owner/PhpstormProjects/shopify/project/functions/outDir/index.js:170:54)
at Module._pile (internal/modules/cjs/loader.js:774:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
at Module.load (internal/modules/cjs/loader.js:641:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:681:19)
at require (internal/modules/cjs/helpers.js:16:16)
at /home/owner/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
at Object.<anonymous> (/home/owner/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/triggerParser.js:53:3)
at Module._pile (internal/modules/cjs/loader.js:774:30)
Share
Improve this question
edited Dec 5, 2019 at 8:48
Peter Haddad
81.1k26 gold badges145 silver badges148 bronze badges
asked Dec 1, 2019 at 8:26
Sean DSean D
4,32213 gold badges53 silver badges99 bronze badges
0
3 Answers
Reset to default 5TLDR: all I did was change:
import functions from 'firebase-functions'
To:
import * as functions from 'firebase-functions`
Explanation: I was using
import functions from 'firebase-functions'
After transpiling from TS to JS, my JS file look like this:
const firebase_functions_1 = __importDefault(require("firebase-functions"));
JS is trying to import the default module exported from firebase-functions. Problem is, when I looked into node_modules/firebase-functions/lib/v1/index.d.ts (this could change in the future), it does not have any default export, therefore my JS code is importing undefined:
// node_modules/firebase-functions/lib/v1/index.d.ts
import * as logger from "../logger";
import * as analytics from "./providers/analytics";
import * as auth from "./providers/auth";
import * as database from "./providers/database";
import * as firestore from "./providers/firestore";
import * as https from "./providers/https";
import * as pubsub from "./providers/pubsub";
import * as remoteConfig from "./providers/remoteConfig";
import * as storage from "./providers/storage";
import * as tasks from "./providers/tasks";
import * as testLab from "./providers/testLab";
import { setApp as setEmulatedAdminApp } from "../mon/app";
export { analytics, auth, database, firestore, https, pubsub, remoteConfig, storage, tasks, testLab, logger, };
export declare const app: {
setEmulatedAdminApp: typeof setEmulatedAdminApp;
};
export * from "./cloud-functions";
export * from "./config";
export * from "./function-builder";
export * from "./function-configuration";
All I did was change:
import functions from 'firebase-functions'
To:
import * as functions from 'firebase-functions`
or just import the https module:
import { https } from 'firebase-functions'
const helloWorld = https.onCall(...)
And you are good to go. Took me a while.
Like you, I wanted to use this ES6 import instead of CommonJS (require()
). You can resolve this by using
import { https } from 'firebase-functions';
I got that answer from here which has a lot more information.
You should do the following:
First import the module firebase-functions
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
Then you can call onRequest()
:
exports.date = functions.https.onRequest((req, res) => {
// ...
});
You can check the documentation here.