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.07k stars 1.19k forks source link

Error: proxyPolicy is not supported in browser environment - Electron App #31480

Open ani-mal opened 4 days ago

ani-mal commented 4 days ago

Describe the bug Unable to make a rest API call on the renderer on the ElectronApp because I get the following error: Error: proxyPolicy is not supported in browser environment. nodeIntegration is set to true and we can't turn this off.

the workaround for this is to run the API request on the main thread, but I would like to remove this workaround and have it all run in the renderer process.

To Reproduce Steps to reproduce the behavior:

  1. Install azure/rest-ai-translation@1.0.0 to an electron app that has nodeIntegration set to true
  2. Make a rest api call to ai translation
  3. See error coming from @azure/core-rest-pipeline that is the dependency tree of @azure/rest-ai-translation

Expected behavior Able to make a rest api request from the renderer process without getting Error: proxyPolicy is not supported in browser environment error.

Screenshots Image

Additional context Unable to provider the source code as it is not open sourced.

github-actions[bot] commented 4 days ago

@deyaaeldeen @jeremymeng @joheredi @maorleger @mpodwysocki @timovv @xirzec

github-actions[bot] commented 4 days ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jeremymeng commented 3 days ago

There were reports of similar issue when using our SDK in Electron app with nodeIntegration: true. We add the proxyPolicy when Node-like environment is detected: https://github.com/Azure/azure-sdk-for-js/blob/31b76c94f5bb633dfa73fe9c20d1ba88a0e9228e/sdk/core/core-rest-pipeline/src/createPipelineFromOptions.ts#L85

But it seems browser version of the policy is bundled.

ani-mal commented 3 days ago

is there any way around this?

xirzec commented 3 days ago

Looks like we need to regenerate and release @azure-rest/ai-translation-text against the 2.x of @azure-rest/core-client -- @MikeyMCZ can you handle this?

ani-mal commented 2 days ago

@xirzec for what its worth we are also using @azure/openai I looked at their latest release and they also seem to be using an older version of @azure-rest/core-client in their dependency tree. And we are also seeing this proxyPolicy error coming from that package dependency as well

deyaaeldeen commented 2 days ago

@ani-mal could you confirm what version of @azure/openai are you using? v2.0.0-beta.2 depends on @azure-rest/core-client@^2.2.0.

ani-mal commented 2 days ago

We are using v1.0.0, I updated it to v2.0.0-beta.2 to check the dependencies, but I think I actually just payed attention to the core-util package as opposed to the core-client version. 🤔