我的Firebase功能有问题。我收到以下错误。
SyntaxError:无法在模块外部使用import语句
下面是我的代码:
import * as functions from 'firebase-functions';
import * as sgMail from '@sendgrid/mail';
sgMail.setApiKey(key);
export const weeklyReminder = functions.pubsub.schedule('every Wednesday 21:00').onRun(async context =>{
const msg = {
to: 'email@gmail.com',
...
};
return sgMail.send(msg);
});
如何导入Firebase函数?
答案 0 :(得分:7)
您使用的是TypeScript还是原始JavaScript?使用纯JavaScript,您将需要使用诸如此类的
:const functions = require('firebase-functions');
此外,将功能更改为与以下相同:
exports.weeklyReminder = functions.pubsub.schedule('every Thursday 21:00').onRun(