Does not run in react-native
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
This issue has been linked to a new work item: W-12659143
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.
Hi, Is there any update on this issue, since I am working on react-native and still facing this issue
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?
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
https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/pull/154 PR here
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.
@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