Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide package as ESM alongside CommonJS module #287

Open
551a1-thijsvoncken opened this issue Aug 2, 2024 · 1 comment
Open

Provide package as ESM alongside CommonJS module #287

551a1-thijsvoncken opened this issue Aug 2, 2024 · 1 comment

Comments

@551a1-thijsvoncken
Copy link

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.

@emilefokkema
Copy link

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.)

@ejizba ejizba added this to the September 2024 milestone Aug 22, 2024
@ejizba ejizba self-assigned this Sep 11, 2024
@ejizba ejizba modified the milestones: September 2024, October 2024 Sep 30, 2024
@ejizba ejizba removed their assignment Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants