React native crypto stream module is undefined

1.7k Views Asked by At

I'm giving a try with [react-native-crypto][1] in order to learn how to convert nodejs to be used in React Native project in the future. Unfortunately, I couldn't get it running successfully. I've faced an issue with stream is undefined. ERROR TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[0], "stream").Transform.call').

If you have ever faced a similar problem, I'm so grateful for your help.

Also, I attach the screenshot of the issue as the following enter image description here

2

There are 2 best solutions below

2
On

I have figured it out by editing in metro.config.js as the following:

resolver: {
    extraNodeModules: {
      stream: require.resolve('stream-browserify'),
    }
  },
0
On

For anyone still trying to solve this issue, I have figured out a solution that worked for me. So within node_modules/cipher-base/index.js, the top of the file should have a line which defines the variable Transform as var Transform = require('stream').Transform. For some reason, it does not like the module stream and as such it needs to be changed to readable-stream. Therefore the variable Transform should now read var Transform = require('readable-stream').Transform.

From what I have gathered, the stream module it is trying to refer to isnt actually a module that can be used. The reason why it gets referenced however seems to be because the tsconfig.json file in the root directory specifies "stream": ["./node_modules/readable-stream"] as a path, almost as if to make stream refer to the readable-stream module, which in theory it should refer to when it is called. But in this case it doesnt happen so we need to explicitly define that we are refering to the readable-stream module.

Hope this helps anyone else out there and prevents others scratching their heads for hours on end like it did for me!