问题
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