Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: Cannot use import statement outside a module Firebase Functions

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 protected]',
        ...
    };
    return sgMail.send(msg);

}); 

How do you import into firebase functions?

like image 384
Chris Evans Avatar asked Jan 16 '20 01:01

Chris Evans


1 Answers

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(
like image 190
Jason Byrne Avatar answered Oct 17 '22 12:10

Jason Byrne