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

286
Views
Cómo importar una función asíncrona y usar await -- error Palabra reservada inesperada 'await'

Tengo un archivo que exporta una función asíncrona, como esta

 // api.js import { getInfo } from "somewhere"; export async function getSomething() { await getInfo() }

y luego intento importarlo a otro archivo como este.

 // Dashboard.vue import { getSomething } from "./api.js"; async created() { await getSomething() },

pero me sale este error

 Syntax Error: Unexpected reserved word 'await'. (77:26) 77 | await getSomething()

Por supuesto, todo esto es pseudocódigo, pero el problema es: ¿por qué mi archivo no reconoce el método importado como una llamada asíncrona? ¿Hay alguna forma diferente de importar algo cuando se trata de un método asíncrono?

editar: tal vez mi código no brinda suficiente contexto, así que aquí hay un mejor ejemplo de cómo estoy consumiendo el método asíncrono

 <template> <div>Hello world</div> </template> <script> import { getSomething } from "./api"; export default { methods: { async init() { await getSomething() } }, async created() { await this.init() } }; </script>

aquí hay una vista exacta de la falla de compilación. getAssessment === getSomething en mi ejemplo anterior

 ERROR Failed to compile with 1 error 1:29:06 AM error in ./src/components/Dashboard.vue?vue&type=script&lang=js& Syntax Error: Unexpected reserved word 'await'. (79:26) 77 | if (user) { 78 | this.user = user; > 79 | this.assessment = await getAssessment(); | ^ 80 | }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba esto:

 // api.js import { getInfo } from 'somewhere' export const getSomething = async () => { return await getInfo(); } // another file import { getSomething } from './api.js' const created = async () => { await getSomething(); } created();
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!