Azure / Azure/azure-functions-nodejs-library
Provide package as ESM alongside CommonJS module
- Dominant language
- TypeScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 6
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](https://nodejs.org/api/esm.html#import-statements) and [issue tracker](https://github.com/nodejs/cjs-module-lexer/issues/88).
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.
Contributor guide
Assessment
This issue has not been assessed yet.