Reputation: 14230
Is it possible to have an import automatically be async.
Right now I have to do this:
main.js
import './import.js'
import.js
(async() => {
const result = await fetch(...);
console.log(result);
})();
But I would rather have it without the self invoking function:
import.js
const result = await fetch(...);
console.log(result);
Upvotes: 2
Views: 652
Reputation: 3172
No you can't. await
must always be inside of an async
block.
See https://tc39.github.io/ecma262/#sec-async-function-definitions
Upvotes: 3