'Stream module in React Native
I want to use a node library which relies on stream (require('stream')) within a React Native project.
This is failing with error stream could not be found within the project because stream is a nodejs package not available in React Native.
What can I do ?
I read that https://github.com/browserify/stream-browserify allows the use of streams in the browser. But how can I make the require('stream') in the library (that I don't control) require stream-browserify instead.
Solution 1:[1]
I had the same problem in my ReactNative project and tried many suggestions, but what finally worked for me was to use the resolver: section in metro.config.js.
My issues were with both stream and crypto.
Here is the resolver section that fixed my problems-
resolver: {
extraNodeModules: {
stream: require.resolve('readable-stream'),
crypto: require.resolve('react-native-crypto-js'),
}
},
Solution 2:[2]
I got the same error and I solved it by just installing the stream:
npm install stream
Solution 3:[3]
I got the same error too and ended up installing:
yarn add streamyarn add events
In my case the issues with dependencies started trying to generate an HMAC with this library: https://github.com/crypto-browserify/createHmac
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | EricN |
| Solution 2 | Sven Eberth |
| Solution 3 | halbano |
