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._compile (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._compile (internal/modules/cjs/loader.js:774:30)
3
Answers
You should do the following:
First import the module
firebase-functions
Then you can call
onRequest()
:You can check the documentation here.
Like you, I wanted to use this ES6 import instead of CommonJS (
require()
). You can resolve this by usingI got that answer from here which has a lot more information.
TLDR: all I did was change:
To:
Explanation: I was using
After transpiling from TS to JS, my JS file look like this:
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:
All I did was change:
To:
or just import the https module:
And you are good to go. Took me a while.