I was attempting to chain two async functions together, because the first had a conditional return parameter that caused the second to either run, or exit the module. Howeve
Even better is to put additional semicolon in front of the code block
;(async () => {
await ...
})();
This prevents auto-formatter (e.g. in vscode) to move the first parenthese to the end of the previous line.
The problem can be demonstrated on the following example:
const add = x => y => x+y
const increment = add(1)
(async () => {
await ...
})();
Without the semicolon, this will be re-formatted as:
const add = x => y => x+y
const increment = add(1)(async () => {
await Promise(1)
})()
which obviously is wrong because it assigns the async function as the y parameter and tries to call a function from the result (which is actually a weird string '1async () => {...}')