2

I am trying to learn cross-platform development with react native for an Instagram feed planner application for Android with Expo cli.

However, I am troubled to include the Instagram private API in my project. I get the error of the title. As I looked into the said crypto package I found that said 'crypto' should be a built-in node module. I don't however find the said module from my project node modules. The only 'crypto' module in my node modules is crypto-random-string.

I might be missing some basic knowledge that would help me fix this but if you know how to make this work I would appreciate any help with it.

Adventune
  • 1,241
  • 1
  • 8
  • 13

2 Answers2

1

Yes, "crypto" is a part of Node built-in packages. However, here you are dealing with a web application, Isn't it? So, this won't be available in this environment.

I'm afraid you need to use some other crypto package. However, before hoping on that solutions you should try these:

  1. In package.json, try adding this:
"devDependencies": {
    ...
},
"browser": {
    "crypto": false
}
  1. In tsconfig.ts file:
"compilerOptions": {
"baseUrl": "./",
"paths": {
  "crypto": [
    "../../node_modules/crypto-js"
  ]
}

You can check here for more details.

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35
  • No, I am working with Android and Expo cli. Should have included that in my post! – Adventune Mar 02 '21 at 10:12
  • Have you tried the above options? Because if they won't work, I am afraid you might need to use some other module which is readily available in Android. – Apoorva Chikara Mar 02 '21 at 10:16
  • I tried those options. Either didn't work. I'll look into other option – Adventune Mar 02 '21 at 10:22
  • @Adventune- I think, you should go through this link https://www.npmjs.com/package/react-native-crypto, it says they are taking leverage of node.js crypto module to work in React-native that might help! – Apoorva Chikara Mar 02 '21 at 10:28
  • @ApoorvaChikara I believe you are correct for bare React Native apps. But, when using expo I believe `react-native-crypto` is not supported. – MikeyE Apr 16 '22 at 20:33
  • Yes, it could be I checked expo is a framework and it is built around react, there might be cases when the existing react package might not support due to peer dependency. I'm not sure just speculating. – Apoorva Chikara Apr 17 '22 at 06:43
1

crypto is a NodeJS built-in module. it's unavailable for react apps.

Ashish Santikari
  • 443
  • 4
  • 19