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";
Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. I think I can't use await.await you have to change your tsconfig as instructed by that error message. But you should be able to use await from inside any function without making those changes.
const config = await import("../test")will return what you want.async (...) => { ... }is literally the definition of an async function.