【问题标题】:How can I fix a parsing issue in React/js如何修复 React/js 中的解析问题
【发布时间】:2021-05-03 18:40:52
【问题描述】:

我的代码:

const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const stripe = require("stripe")(
  "sk_test"
);

const app = express();

app.use(cors({ origin: true }));
app.use(express.json());

app.post("/payments/create", async (request, response) => {
  const total = request.query.total;

  console.log("Payment Request Recieved for: ", total);

  const paymentIntent = await stripe.paymentIntents.create({
    amount: total, 
    currency: "usd",
  });

  response.status(201).send({
    clientSecret: paymentIntent.client_secret,
  });
});
exports.api = functions.https.onRequest(app);

问题出在这一行:Image of the source of issue

出现的错误信息是: 解析错误:意外的令牌 =>

我已尝试重新安装所有内容,但似乎没有任何效果

如果我能得到任何帮助,我将不胜感激

【问题讨论】:

    标签: javascript reactjs firebase


    【解决方案1】:

    您使用的是什么版本的 Node?新服务器似乎不太可能使用不支持箭头功能的旧版本,但您应该通过运行node -v 进行检查。然后检查compatibility chart

    如果您的版本不支持箭头功能并且您无法更新,您可以使用function (request, response) { ... } 重写该功能,但我希望您也会遇到async/await 模式的问题。

    相关回答:https://stackoverflow.com/a/36843758/12474862

    【讨论】:

      猜你喜欢
      • 2016-01-28
      • 1970-01-01
      • 2021-04-06
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多