Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
How do I fix error: "Parsing error: Unexpected reserved word 'await'. (10:22)eslint"?

As per the title, I want to solve this error message:"Parsing error: Unexpected reserved word 'await'. (10:22)eslint"

This is my current, working code snippet:

import { WebClient } from '@slack/web-api';
import { prSummaryBotEnvVariables } from '../pr-summary-bot-env/env-exported-variables.js';
import { getUsersFirstAndLastName, removeUndefinedValuesFromArray } from '../utils/utils.js';

const botToken = prSummaryBotEnvVariables();
const client = new WebClient(botToken.botUserOauthToken);
let slackUserEmails;

const client = new WebClient(botToken.botUserOauthToken);
let slackUserEmails;

try {
  const { members } = await client.users.list();
  slackUserEmails = members.map(member => member.profile.email);
} catch (error) {
  console.error(error);
}

const slackUserNames = removeUndefinedValuesFromArray(getUsersFirstAndLastName(slackUserEmails));

export { slackUserNames };

I'm just using Slack API to get all our members' usernames & do some manipulation with it before exporting the array. I tried this solution with two inner async keywords, but it didn't work. How can I refactor this?

Update:

I tried this solution, but I just get an empty array:

import { WebClient } from '@slack/web-api';
import { prSummaryBotEnvVariables } from '../pr-summary-bot-env/env-exported-variables.js';
import { getUsersFirstAndLastName, removeUndefinedValuesFromArray } from '../utils/utils.js';

const botToken = prSummaryBotEnvVariables();
const client = new WebClient(botToken.botUserOauthToken);
let slackUserEmails;
const slackUserNames = [];

(async () => {
  try {
    const { members } = await client.users.list();
    slackUserEmails = members.map((member) => member.profile.email);
  } catch (error) {
    console.error(error);
  }

  slackUserNames.push(removeUndefinedValuesFromArray(getUsersFirstAndLastName(slackUserEmails)));
})();

console.log(slackUserNames); // empty array
export { slackUserNames };

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As mentioned in the comments, you cannot use the await keyword outside of async functions. For that same reason, you won't be able to export slackUserNames as a variable, as it depends on previously executing asynchronous code.

A straightforward approach would be to export an asynchronous function from your file that you could use in other parts of your project then:

import { WebClient } from '@slack/web-api';
import { prSummaryBotEnvVariables } from '../pr-summary-bot-env/env-exported-variables.js';
import { getUsersFirstAndLastName, removeUndefinedValuesFromArray } from '../utils/utils.js';
export async function getSlackUserNames() {

    const botToken = prSummaryBotEnvVariables();
    const client = new WebClient(botToken.botUserOauthToken);
    let slackUserEmails;

    const client = new WebClient(botToken.botUserOauthToken);
    let slackUserEmails;

    try {
        const {members} = await client.users.list();
        slackUserEmails = members.map(member => member.profile.email);
    } catch (error) {
        console.error(error);
    }

    const slackUserNames = removeUndefinedValuesFromArray(getUsersFirstAndLastName(slackUserEmails));

}

Now you could call this function somewhere else in your project:

const slackUserNames = await getSlackuserNames();
console.log("Slack users are: ", slackUserNames);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!