SyntaxError:无法在模块Firebase函数外部使用import语句 [英] SyntaxError: Cannot use import statement outside a module Firebase Functions

查看:81
本文介绍了SyntaxError:无法在模块Firebase函数外部使用import语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Firebase功能有问题.我收到以下错误.

I'm, having an issue with my Firebase function. I'm getting the below error.

SyntaxError:无法在模块外部使用import语句

SyntaxError: Cannot use import statement outside a module

下面是我的代码:

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函数?

How do you import into firebase functions?

推荐答案

您正在使用TypeScript还是原始JavaScript?使用普通的JavaScript,您将需要使用诸如此类的

Are you using TypeScript or vanilla JavaScript? With plain JavaScript you'd use require like this:

const functions = require('firebase-functions');

此外,将功能更改为与以下相同:

Also, change the function to be the same as the below:

exports.weeklyReminder = functions.pubsub.schedule('every Thursday 21:00').onRun(

这篇关于SyntaxError:无法在模块Firebase函数外部使用import语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆