简体   繁体   English

如何修复节点中的“解析错误:意外的令牌 =>”?

[英]how to fix 'parsing error: Unexpected token =>' in node?

I am using firebase functions for stripe payment integration.我正在使用 firebase 功能进行条带支付集成。 This particular function used for register customer with stripe.这个特殊的 function 用于注册客户与条纹。

Node version 10.15.3,节点版本 10.15.3,

npm version 6.9.0, npm 6.9.0版,

"ecmaVersion": 6 in.eslintrc.json “ecmaVersion”:6 英寸 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该代码与 github 示例https上提供的 firebase 平台相同。

Parsing error: Unexpected token =>解析错误:意外的令牌 =>

and if I change the "ecmaVersion": 6 to "ecmaVersion": 8 in.eslintrc.json如果我将 "ecmaVersion": 6 更改为 "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我想正确部署 function 以便用户可以在 firebase 存储中的条带和日期存储上注册

Make sure you are running in your local machine node >= 8. For deployment, you should have in your package.json.确保您在本地机器节点上运行 >= 8。对于部署,您应该在 package.json 中有。

{
    //...
    "engines": {
        "node": "8"
    },
    //...  
}

For eslint, to enable parsing for async functions, you should include this in your config:对于 eslint,要启用异步函数解析,您应该在配置中包含以下内容:

{
    "parserOptions": {
        "ecmaVersion": 2017
    }
}

Looks like you're talking about an eslint error.看起来你在谈论一个 eslint 错误。 I've been able to reproduce it in the eslint demo page using ecmaVersion 2015.我已经能够使用 ecmaVersion 2015 在 eslint 演示页面中重现它。

I just changed it to ecmaVersion 2017 (the version from when async/await was supported) and the error has gone away ( link ).我只是将其更改为 ecmaVersion 2017(支持async/await时的版本)并且错误消失了( 链接)。

Also, verified the eslint config in the project you're talking about.另外,验证了您正在谈论的项目中的 eslint 配置。 It's ecmaVersion 2017: link这是 ecmaVersion 2017: 链接

I am new to React-native + firebase function.我是 React-native + firebase 功能的新手。 But with these lines of code, lint issue went out and I can now deploy firebase functions.但是有了这些代码行,lint 问题就解决了,我现在可以部署 firebase 函数了。

Old老的

{
  "$schema": "./node_modules/@react-native-firebase/app/firebase-schema.json",
  "react-native": {
    "crashlytics_auto_collection_enabled": true,
    "crashlytics_debug_enabled": true,
    "messaging_android_notification_channel_id": "high-priority",
    "messaging_ios_auto_register_for_remote_messages": true
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  }
}

New新的

{
  "$schema":"./node_modules/@react-native-firebase/app/firebase-schema.json",
  "react-native": {
      "crashlytics_auto_collection_enabled": true,
      "crashlytics_debug_enabled": true,
      "messaging_android_notification_channel_id": "high-priority",
      "messaging_ios_auto_register_for_remote_messages":true
    }
}

This solved my issue这解决了我的问题

{...
   "parserOptions": {
   "ecmaVersion": 8
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有最新节点版本的异步 Function 上的“解析错误:意外令牌功能” - "Parsing Error: unexpected token function" on Async Function with a recent Node version 包括异步 Function Firebase Cloud Functions 内(eslint“解析错误:意外的令牌函数”) - Including Async Function Within Firebase Cloud Functions (eslint "Parsing error: Unexpected token function") 部署 Firebase 和 Node.js 应用程序导致错误:Error: Parse Error in remoteconfig.template.json: Unexpected token 'i' at 1:1 - Deploying Firebase and Node.js application results in error: Error: Parse Error in remoteconfig.template.json: Unexpected token 'i' at 1:1 Firebase 云函数部署错误 - SyntaxError: Unexpected token '?' - Firebase Cloud Functions Deploy Error- SyntaxError: Unexpected token '?' 运行 firebase 部署时,在 flutter 应用程序上 1:1 时解析错误意外令牌 '��' - Parse error Unexpected token '�' at 1:1 ��{ on flutter app when running firebase deploy 当我将 firebase 与节点 js 连接时。 我得到了这个错误。 我如何修复此错误并将 firebase 连接到 node express 项目 - when I connecting firebase with node js. I got this error. how I fix this error and connect firebase to node express project AWS CDK:AWS-ec2 SyntaxError:意外的令牌“。” 更新节点后 - AWS CDK: AWS-ec2 SyntaxError: Unexpected token '.' after update node 在 gcloud 上调试节点应用程序以修复 500 服务器错误 - Debugging a node app on gcloud to fix 500 server error 搜索到 Cloud Run 实例错误的 Google Cloud Secret:“SyntaxError: Unexpected token ':'” - Google Cloud Secret hunted to Cloud Run Instance Error: "SyntaxError: Unexpected token ':'" 错误:意外标记:< @ 第 1 行,第 1 列。<!--?xml version="1.0" encoding="utf-8"?--> - error:unexpected token: < @ line 1, column 1. <?xml version="1.0" encoding="utf-8"?>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM