0
votes

When deploying my cloud functions using the command firebase deploy I am getting this error for all of my functions:

!  functions[deleteGame-DeleteGameFunction(us-central1)]: Deployment error.
Function load error: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'glob'
    at Function.Module._resolveFilename (module.js:476:15)
    at Function.Module._load (module.js:424:25)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/user_code/index.js:11:14)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)

This is my index.js file (I got it from here):

'use strict';
/** EXPORT ALL FUNCTIONS
 *
 *   Loads all `.f.js` files
 *   Exports a cloud function matching the file name
 *   Author: David King
 *   Edited: Tarik Huber
 *   Based on this thread:
 *     https://github.com/firebase/functions-samples/issues/170
 */
const glob = require("glob");
const camelCase = require("camelcase");
const files = glob.sync('./**/*.f.js', { cwd: __dirname, ignore: 
'./node_modules/**'});
for(let f=0,fl=files.length; f<fl; f++){
  const file = files[f];
  const functionName = camelCase(file.slice(0, -5).split('/').join('_')); // 
Strip off '.f.js'
  if (!process.env.FUNCTION_NAME || process.env.FUNCTION_NAME === 
functionName) {
    exports[functionName] = require(file);
  }
}

This index.js file is a way to organize your firebase cloud functions that I found on https://postmarkapp.com/blog/sending-transactional-emails-via-firebase-and-cloud-functions that got it from https://codeburst.io/organizing-your-firebase-cloud-functions-67dc17b3b0da Thank you for your help!

1
I think you need to install glob module too. like npm install --save glob - HakanC

1 Answers

2
votes

It sounds like you need to run this from your functions directory:

npm install glob

And probably also

npm install camelcase

You can't require a module without first installing it into your project like this.