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
SyntaxError: Unexpected reserved word "await"

I keep getting this error even thought I am in a asynchronous function...

import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export async function importer(client) {
    const dir = join(__dirname, "../../commands/")

    const commandCategories = readdirSync(dir)
    for (let cat of commandCategories) {
        const commandFiles = readdirSync(join(dir, cat)).filter(files => files.endsWith(".js"));

        for (const file of commandFiles) {
            const command = await import(join(dir, cat, file));
            client.commands.set(command.default.name, command.default);
        }
    }
}

Is there something I am missing? I definitely need the await part in import in const command. It imports a few commands then it drops the mentioned error in title on the console output.

Thanks.

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

0

The problem isn't the importer code, it's in one of the modules you attempted to import (and import crashes on parsing it)!

It's a bug in node that such a non-helpful error is thrown when this syntax error is encountered during dynamic import.

Try logging the filenames before importing them so you can see at which file it crashes. Once you know which file failed to parse, do a static import of it for testing, so you can get a proper error that tells you which line has the issue.

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!