I am using firebase functions for stripe payment integration. This particular function used for register customer with stripe.
Node version 10.15.3 ,
npm version 6.9.0 ,
"ecmaVersion": 6 in .eslintrc.json
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const stripe = require('stripe')(functions.config().stripe.testkey)
exports.createStripeCustomer = functions.auth.user()
.onCreate(async (user) => {
const customer = await
stripe.customers.create({email: user.email});
await admin.firestore()
.collection('stripe_customers')
.doc(user.uid)
.set({customer_id: customer.id});
});
The code is same as the firebase platform provide on github example https://github.com/firebase/functions-samples/blob/master/stripe/functions/index.js
Parsing error: Unexpected token =>
and if I change the "ecmaVersion": 6 to "ecmaVersion": 8 in .eslintrc.json
then error is .onCreate(async (user) => {
^
SyntaxError: Unexpected token (
I want to deploy function properly so that user can register on stripe and date store in firebase storage
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided. This might be a simple typo.
Here are some of the most common causes of the Android parse error: The app is not compatible with your device. Your phone does not have permission to install the app. The file you are trying to install is corrupt, incomplete, or damaged.
The Best Answer is. Unexpected token errors in ESLint parsing occur due to incompatibility between your development environment and ESLint's current parsing capabilities with the ongoing changes with JavaScripts ES6~7. The solution is to have ESLint parsed by a compatible parser.
Make sure you are running in your local machine node >= 8. For deployment, you should have in your package.json.
{
//...
"engines": {
"node": "8"
},
//...
}
For eslint, to enable parsing for async functions, you should include this in your config:
{
"parserOptions": {
"ecmaVersion": 2017
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With