Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda