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 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.
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./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.
4 Answers
Reset to default 7I 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'),
}
},
I got the same error too and ended up installing:
yarn add stream
yarn add events
In my case the issues with dependencies started trying to generate an HMAC with this library: https://github./crypto-browserify/createHmac
I got the same error and I solved it by just installing the stream:
npm install stream
Just had a similar issue. You can install the react native-friendly package stream-browserify
as stream
with npm install stream@npm:stream-browserify