简体   繁体   中英

Why does async + await return AsyncFunction?

code

const config = async () => {
  return await import("../test");
}

console.log(config);

../test

export const config = {
  value1: 1,
  value1: 2,
};

I want config in../test but this returns [AsyncFunction: config] .

async () => {} is a function declaration. So you assigned config to a function.

You have to call that function, and await the result, in order to get the value you want.

console.log(await config());

But are you sure you want a dynamic import here?

Because this should do the same thing without any headaches at all.

import { config } from "../test";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM