我一直在关注codelabs教程here,将我的第一个函数部署到firebase . 我已经完成了本教程的第8步("Welcome new users") .
当我从functions子目录中运行 firebase deploy --only functions
时,部署看起来很成功:
Marks-MacBook-Air-3:函数mf $ firebase deploy --only functions ===部署到'friendlychat-21221'...我正在部署函数运行命令:npm --prefix“$ RESOURCE_DIR”运行lint函数@lint / Users / mf / Desktop / friendlychat-web / cloud-functions-start / functions eslint . ✔功能:完成运行预部署脚本 . 我的功能:确保启用必要的API ...✔功能:启用所有必要的API我的功能:准备上传功能目录...✔部署完成!
但是看看我的firebase仪表板,看起来它们看起来并不像它们一样:
我甚至不确定从何处开始进行故障排除,因为 Cloud 功能选项卡中的日志为空 .
有没有人遇到这个和/或有一个很好的故障排除策略?
更新时间:2018年5月25日星期五下午1:15:这是我在函数子目录中的index.js文件:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// TODO(DEVELOPER): Write the addWelcomeMessages Function here.
// Adds a message that welcomes new users into the chat.
exports.addWelcomeMessages = functions.auth.user().onCreate(user => {
console.log('A new user signed in for the first time.');
const fullName = user.displayName || 'Anonymous';
// Saves the new welcome message into the database
// which then displays it in the FriendlyChat clients.
return admin.database().ref('messages').push({
name: 'Firebase Bot',
photoUrl: '/images/firebase-logo.png', // Firebase logo
text: `${fullName} signed in for the first time! Welcome!`, // Using back-ticks.
}).then(() => {
console.log('Welcome message written to database.');
});
});
// TODO(DEVELOPER): Write the blurOffensiveImages Function here.
// TODO(DEVELOPER): Write the sendNotifications Function here.
以下是functions子目录的内容:
2 回答
尝试
Firebase list
列出登录帐户下firebase中的所有项目,并查看您要部署的项目是否显示 . 如果它没有显示尝试这个:firebase logout && firebase login
firebase list
firebase use <alias_or_project_id>
firebase deploy --only functions
或firebase deploy --only functions:<function_name>
希望这可以帮助!
我改变了两件事后最终得到了它(我不确定哪一个解决了这个问题;也许两者都有):
在部署函数之前,从函数目录中运行
运行
npm install
(应该在父目录中完成) .请注意,当您运行
firebase init
并导致覆盖index.js文件时,该文件可能只有一个注释掉的'helloWorld'函数...