0

Prior to the post, I would like to make it clear that I am very very new to all this (node, eslint, firebase).

So right now I'm writing a proof of concept for a Roblox game/group I'm developing. This however has nothing to do with my issue, my issue comes when I try to compile an asynchronous function. I get the error

Parsing error: Unexpected token =>

A friend of mine took the same snippet of code and apparently it works fine for them. I'm genuinely at a loss, everything looks like it should work.

Node version is 14.17.3

Here's my code

const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const app = express();
const fs = require("fs");
const Webhook = require("discord-webhook-node").Webhook;
const URL = "EXPUNGED";
const hook = new Webhook(URL);
const tmp = require("tmp");
const noblox = require("noblox.js");
const cookie = "EXPUNGED";

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

app.post("/api/rank", async (req, res) => {
  const currentUser = await noblox.setCookie(cookie);
  functions.logger.log(`Logged in as ${currentUser.UserName} [${currentUser.UserID}]`);
  const groupInfo = await noblox.getGroup(000000);
  functions.logger.log(groupInfo);
  res.end("Received POST request!");
}
);
exports.widgets = functions.https.onRequest(app);

The reason there are more variables at the top than I use in the block is that it's for other parts of the script. They don't affect the code block in any way.

If you need further information that I failed to provide let me know.

jrdonat
  • 5
  • 2

1 Answers1

0

You don't compile JavaScript. If eslint is causing this issue, then your eslint settings may need to specify something later than ES5.

Otherwise, you can rewrite it as ES5, without the arrow function:

app.post("/api/rank", async function (req, res) {

If the async keyword causes an issue, see the eslint config in this answer.

Josh Wulf
  • 4,727
  • 2
  • 20
  • 34