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

Does not work with React Native Expo SDK 42+ Please Remove Isomorphic-Webcrypto #22628

Closed
charlestbell opened this issue Jul 18, 2022 · 23 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team

Comments

@charlestbell
Copy link

Currently building a React Native app and just finished porting it over from Firebase to CosmosDB.

Everything looked great, but when I went build it for deployment, I get this error on eas build:
❌ ld: 12 duplicate symbols for architecture arm64

Turns out, I am by no means the first. Others in the community narrowed down the problem to a package called @unimodules/core, which is a dependency of isomorphic-webcrypto, which is a dependency of @azure/cosmos.

The issue has been open on the isomorphic-webcrypto package for some time kevlened/isomorphic-webcrypto#65

But that package has only one maintainer, and hasn't been updated in over a year.

Because there is no movement on the isomorphic-webcrypto package, I am asking that the Azure Team please remove isomorphic-webcrypto as a dependency, so that react-native Expo devs can use an up-to-date version of Expo.

Thank you so much!

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jul 18, 2022
@azure-sdk
Copy link
Collaborator

Label prediction was below confidence level 0.6 for Model:ServiceLabels: 'Azure.Core:0.40485868,Storage:0.09189288,Cosmos:0.0918496'

@xirzec xirzec added the Cosmos label Jul 19, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 19, 2022
@xirzec xirzec added the Client This issue points to a problem in the data-plane of the library. label Jul 19, 2022
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jul 19, 2022
@xirzec
Copy link
Member

xirzec commented Jul 19, 2022

@jeremymeng can you look into this and make a recommendation for how to best resolve?

@jeremymeng
Copy link
Member

jeremymeng commented Jul 19, 2022

cosmos uses isomorphic-webcrypto for sha-256 digest and hmac computation when targeting React Native. We could change to not explicitly require this package, and instead rely on customers to provide necessary crypto polyfill.

const globalCrypto = require("isomorphic-webcrypto"); // eslint-disable-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports

In app config we use computerSha256Hash and computerSha256Hmac from @azure/core-util. On React Native, it falls back to the browser version, which requires the importKey, sign, and digest from crypto.subtle API.

Our current sample provides the polyfill using isomorphic-webcrypto though as it is the only one that I know of and tested on Android Emulator.

import * as crypto from "isomorphic-webcrypto";
global.crypto = crypto;

If isomorphic-webcrypto doesn't work on iOS then we need another polyfill.

Another approach is to provide digest/hmac functionality using RN-native packages. But I haven't found any "blessed" packages for this.

@charlestbell
Copy link
Author

Update: I found a temporary workaround, which is to use Expo's classic build service, instead of their newer EAS build service. Unfortunately, the classic build service is deprecated and goes offline in about 160 days. So I'm reaching out to them and see if they can get EAS build to work like classic in this regard, or hold off on deprecating classic.

Thanks @jeremymeng and @xirzec for looking into it. I wish you luck finding another polyfill.

@charlestbell
Copy link
Author

@xirzec
Copy link
Member

xirzec commented Jul 19, 2022

Update: I found a temporary workaround, which is to use Expo's classic build service, instead of their newer EAS build service. Unfortunately, the classic build service is deprecated and goes offline in about 160 days. So I'm reaching out to them and see if they can get EAS build to work like classic in this regard, or hold off on deprecating classic.

Glad you found a workaround for now. If they have any recommendations for replacing isomorphic-webcrypto or if you stumble into such in your travels, let us know, we'll keep working on the problem for our side.

@charlestbell
Copy link
Author

Update: can confirm that this issue is affecting android builds on Expo EAS, not just ios.

Any progress on removing isomorphic-webcrypto?

@jeremymeng
Copy link
Member

jeremymeng commented Sep 8, 2022

@charlestbell I opened a draft PR #23156. Please give try the package produced by the CI automation. If I understand correctly, removing the dependency would hopefully fix the build errors, but you would get runtime error when using cosmos, unless you provide crypto polyfills.

Edited: remove link to old artifact

@jeremymeng
Copy link
Member

PR #23156 doesn't work in my testing. I will spend some more time on this then get back to you.

@jeremymeng
Copy link
Member

@charlestbell here's an updated version that I was able to use to run some cosmos test in Android Emulator (with polyfills). Please give it a try

@charlestbell
Copy link
Author

charlestbell commented Sep 14, 2022

Thank you, I'll take a look. This will be my first time using a non-npm package, you'll have to bear with me.

@charlestbell
Copy link
Author

I pasted the updated package slice inside my node modules folder in @azure/cosmos, but I'm still fuzzy on how to polyfill crypto.
I did some digging and came up with rn-nodify.js but that option is looking scary.
What did you use @jeremymeng?

@jeremymeng
Copy link
Member

jeremymeng commented Sep 15, 2022

@charlestbell I was able to use isomorphic-webcrypto on Android Emulator. Here's my shim.js which I import at the beginning of app.js before importing Azure SDK packages.

import "react-native-url-polyfill/auto";
import "react-native-get-random-values";
import "text-encoding-polyfill";
const getRandomValues = global.crypto.getRandomValues;
import * as crypto from "isomorphic-webcrypto";
global.crypto = crypto;
global.crypto.getRandomValues = getRandomValues;

@charlestbell
Copy link
Author

Pardon my ignorance, but if this is still using isomorphic-webcrypto. Then how does it help me with my problem?

@charlestbell
Copy link
Author

I don't have an issue with Android Emulator, I have an issue with Expo Application Services' build process, using the eas-cli.

@jeremymeng
Copy link
Member

Pardon my ignorance, but if this is still using isomorphic-webcrypto. Then how does it help me with my problem?

@charlestbell My PR removes cosmos' hard-coded require dependency on isomorphic-webcrypto so expo will not load it during build time, and customers have an opportunity to provide their own crypto polyfill. At this point I don't know about other crypto polyfill that would satisfy EAS build. Maybe expo team has more insights on this?

@charlestbell
Copy link
Author

Understood. Thank you.

I don't know where to find a polyfill either, so I'm in the same boat.

Thanks for doing what you've done though. If anyone knows of another polyfill, I'll give it a try with the version you provided.

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-js that referenced this issue Feb 22, 2023
Add flush rest api specs  (Azure#22628)

* Adds base for updating Microsoft.Cache from version preview/2022-11-01-preview to version 2023-03-01-preview

* Updates readme

* Updates API version in new specs and examples

* Adding flush rest api specs

* Add pattern for cluster and database parameters

* Minor changes

* fix lint error . 2. Revert parameter pattern change
 Please enter the commit message for your changes. Lines starting

* updating the texts

* Make the ids of the flush parameters to be optional
@xirzec xirzec added feature-request This issue requires a new behavior in the product in order be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 30, 2023
@MaxJadav
Copy link

MaxJadav commented Jul 21, 2023

Getting issue without expo
#26574

kevlened/isomorphic-webcrypto#78

@faisalaltell12
Copy link
Contributor

Can isomorphic-webcrypto be replaced with expo-crypto? Getting the same issue as well.

@faisalaltell12
Copy link
Contributor

Can isomorphic-webcrypto be replaced with expo-crypto? Getting the same issue as well.

The problem is @azure/cosmos has a dependency on isomorphic-webcrypto:
https://www.npmjs.com/package/isomorphic-webcrypto?activeTab=dependencies

isomorphic-webcrypto has a dependency on @unimodules/core - @unimodules/core is deprecated.

Maybe we could update isomorphic-webcrypto to not have a dependency on @unimodules/core?

@oreHGA
Copy link

oreHGA commented Sep 19, 2023

At this point I don't know about other crypto polyfill that would satisfy EAS build. Maybe expo team has more insights on this?

@jeremymeng I think you can probably use the react-native-webview-crypto package and create a polyfill that supports web.crpyto calls. There's an example that works in the github link

https://github.com/webview-crypto/react-native-webview-crypto

Just used it for a private project where I couldn't use isomorphic-webcrypto

@nelsona
Copy link

nelsona commented Feb 26, 2024

There is a fork here that removes the @unimodules/core dependency and uses expo-crypto:
https://github.com/earonesty/isomorphic-webcrypto

For this to work with eas build I think you would need to add the following to the the package.json for this fork:

  "react-native": {
    "./src/main.js": "./src/react-native.js",
    "./src/index.mjs": "./src/react-native.js"
  },

Copy link

Hi @charlestbell, we deeply appreciate your input into this project. Regrettably, this issue has remained unresolved for over 2 years and inactive for 30 days, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Cosmos customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
None yet
Development

No branches or pull requests

8 participants