SyntaxError: Cannot use import statement outside a module Firebase Functions

帅比萌擦擦* 提交于 2020-12-30 07:23:28

问题


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

SyntaxError: Cannot use import statement outside a module

below is my code:

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

}); 

How do you import into firebase functions?


回答1:


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(


来源:https://stackoverflow.com/questions/59761839/syntaxerror-cannot-use-import-statement-outside-a-module-firebase-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!