最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Stream module in React Native - Stack Overflow

programmeradmin7浏览0评论

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.

Share Improve this question asked Mar 1, 2021 at 22:04 WeierWeier 1,4292 gold badges13 silver badges23 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

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'),
  }
},

I got the same error too and ended up installing:

  1. yarn add stream
  2. 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

发布评论

评论列表(0)

  1. 暂无评论