Description
Currently @azure/functions only provides a CommonJS module. Due to limitation in Node/Webpack's ESM interop, this makes it impossible to import most named exports from an ESM package. This means that HttpRequest
, for example, cannot be imported and used as a class (for testing purposes).
Repro steps
A minimal reproduction can be seen here: https://stackblitz.com/edit/stackblitz-starters-c4ytl9?file=index.js
Expected behavior
I expect this example to work and log the HttpRequest class to the console.
Actual behavior
A SyntaxError is thrown.
Known workarounds
This can be worked around by only using the default import.
Related information
Eventually the issue seems to be caused by NodeJS's interop between CJS and ESM.
More information can be found in NodeJS's documentation and issue tracker.
Both NodeJS and Webpack have indicated they don't intend to fix this issue. However, it is pretty common these days for NPM packages to provide both ESM and CJS versions. If @azure/functions were to provide an ESM export, this would solve the issue.