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 run in react-native #108

Open
anutting opened this issue Jan 12, 2023 · 8 comments
Open

Does not run in react-native #108

anutting opened this issue Jan 12, 2023 · 8 comments
Labels

Comments

@anutting
Copy link

anutting commented Jan 12, 2023

I installed this module in my react-native project, but receive an error:

error: Error: While trying to resolve module `crypto` from file `my-project/node_modules/commerce-sdk-isomorphic/lib/index.cjs.js`, 

It seems like this module requires node's crypto package that is not available in react-native.

Please provide a workaround, alternative module, or fix for this issue I can use the commerce-sdk in react-native.

Thank you

@git2gus
Copy link

git2gus bot commented Mar 8, 2023

This issue has been linked to a new work item: W-12659143

@joeluong-sfcc
Copy link
Contributor

Hi @anutting, thanks for creating this issue. A work item in our backlog has been created and we'll loop you back in with any updates.

@asad-pwc
Copy link

Hi,
Is there any update on this issue, since I am working on react-native and still facing this issue

@bendvc
Copy link

bendvc commented Feb 16, 2024

Hi, Is there any update on this issue, since I am working on react-native and still facing this issue

Hi @asad-pwc, I don't think the team will have time to look into this as we do not normally use react native and would have to ramp up. However it does look like this problem isn't specific to our lib, there is a shim that was created here that you can probably use to resolve your problem. Have you given that a try?

@FerVillanuevas
Copy link

i already fix this.

The issue its on helpers, because RN did not hava a Crypto lib, insted of expo-crypto.

So we should create an alieas expo-crypto to crypto

To do that install this plugin https://www.npmjs.com/package/babel-plugin-module-resolver
and update the configuration on: babel.config.js
plugins: [ [ "module-resolver", { alias: { crypto: "expo-crypto", }, }, ], ],

Then on the library we should verify if is RN, Brower or Node.

if ( typeof navigator !== 'undefined' && navigator.product === 'ReactNative' ) { challenge = (await crypto.digestStringAsync?.('SHA-256', codeVerifier, { encoding: 'base64', })) || ''; } else { challenge = urlSafe( crypto.default .createHash('sha256') .update(codeVerifier) .digest('base64') ); }

i will create a PR, but dont know if will get aprroved

@FerVillanuevas
Copy link

#154 PR here

@samskinner-joann
Copy link

Hi, was considering this for a React Native app, but upon seeing this am I to assume this library is not fit for use and I should create a from scratch integration with SLAS? Thanks.

@joeluong-sfcc
Copy link
Contributor

@samskinner-joann That is correct, this package does not support react native out of the box. One potential solution if you don't want to create the SLAS requests from scratch is to fork this repo and make the necessary modifications to get the commerce-sdk-isomorphic working with react native and use the modified library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants