firebase云功能部署glob错误

问题描述 投票:0回答:1

使用命令firebase deploy部署我的云功能时,我收到了所有函数的错误:

!  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)

这是我的index.js文件(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);
  }
}

这个index.js文件是一种组织我在https://postmarkapp.com/blog/sending-transactional-emails-via-firebase-and-cloud-functions上找到的firebase云功能的方法,它来自https://codeburst.io/organizing-your-firebase-cloud-functions-67dc17b3b0da感谢您的帮助!

javascript firebase google-cloud-functions glob
1个回答
1
投票

听起来你需要从你的函数目录运行它:

npm install glob

也许还有

npm install camelcase

如果没有先将模块安装到您的项目中,就不能require模块。

© www.soinside.com 2019 - 2024. All rights reserved.