You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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.
The text was updated successfully, but these errors were encountered:
There is also an inconsistency now, because the Typescript declaration suggests that HttpRequest is available as a named export that is not just a type but also a value (specifically, a class), whereas if you actually use this package in a Typescript context (which implies ESM import syntax), HttpRequest will, when the code runs (which will be in Node), not be available from the Javascript module as a named export. (Except, that is, if you use a bundler.)
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.
The text was updated successfully, but these errors were encountered: