Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.06k stars 1.19k forks source link

Add ESM support for @azure/identity #27804

Open rewrlution opened 10 months ago

rewrlution commented 10 months ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] I tried to use @azure/identity in an ESM only application, but ran into an issue. The root cause is that @azure/identity has a dependency on a CJS module: open.

Describe the solution you'd like I want to use @azure/identity in an ESM only environment.

xirzec commented 10 months ago

@rewrlution ESM support is definitely on our roadmap, but can you clarify what runtime you're targeting? Are you using node's native ESM support, bun, deno, or some kind of bundler for browsers?

github-actions[bot] commented 10 months ago

Hi @rewrlution. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] commented 10 months ago

Hi @rewrlution, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

rewrlution commented 9 months ago

Here's the scenario:

  1. Our libraries are purely ESM
  2. One of the dependencies of our libraries is @azure/identity. More specifically, the azureTokenCredentials class.
  3. However, since @azure/identity has a dependency on open, which is CJS, it causes some incompatibility issue.
rewrlution commented 9 months ago

My question is: do you have the ESM version of the @azure/identity library?

xirzec commented 9 months ago

My question is: do you have the ESM version of the @azure/identity library?

Not today, but I believe it will be one of the first to support ESM natively besides core. /cc @mpodwysocki who is working on the core ESM migration

rewrlution commented 9 months ago

Got it. Any chance that your team has an ETA for the ESM migration?

xirzec commented 9 months ago

Got it. Any chance that your team has an ETA for the ESM migration?

I don't have a specific ETA, though we don't plan to ship a new version of Identity this month in order to avoid introducing bugs during the holidays.

I think open is only used for the InteractiveBrowserCredential so if you don't need that credential type you may be able to configure things such that it is never loaded/used. For example, I think you could use overrides in your package.json to replace open with a local stub written in ESM package that exports a no-op function.

rewrlution commented 9 months ago

@xirzec thanks for your reply! Yes, we realized that open is only used for the interactive flow while all we need is the client credential flow. and yes, this is what we are doing right now, using the overrides option.

Got it.

xirzec commented 9 months ago

@rewrlution glad you were able to mitigate. We'll keep working on official ESM support so that hopefully this won't be needed in the future.

rewrlution commented 9 months ago

Thanks @xirzec

wfairclough commented 7 months ago

I am running into this issue using Node v20 in AWS Lambda bundled for ESM. Will do the overrides workaround for now

Stadly commented 1 week ago

Any news on this?