使用命令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上从https://codeburst.io/organizing-your-firebase-cloud-functions-67dc17b3b0da获得的firebase云功能的方法 谢谢您的帮助!
答案 0 :(得分:1)
听起来您需要在功能目录中运行它:
callc#function(string val){
......//my codes
}
也许也是
npm install glob
如果不先将模块安装到项目中,就无法npm install camelcase
。