.\node_modules\instagram-private-api\dist\repositories\request.js: crypto could not be found within the project

Viewed 411

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.

2 Answers

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.

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

Related