Chris
Chris

Reputation: 14230

js use async as default in import

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

Answers (1)

bcherny
bcherny

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

Related Questions