Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading