6

The following error showed in my metro bundler when I run react-native with npm plugin @woocommerce/api library. It's currently active plugin for woocommerce rest api.
I've searched many solutions about the stream dealing with cipher-base. It doesn't work. I've also deleted node_modules and reinstall again. And then, npm start -- --reset-cache. Nothing Works for me. Please, help me out.

error: Error: Unable to resolve module stream from C:\**\node_modules\cipher-base\index.js: stream could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  1 | var Buffer = require('safe-buffer').Buffer
> 2 | var Transform = require('stream').Transform
    |                          ^
  3 | var StringDecoder = require('string_decoder').StringDecoder
  4 | var inherits = require('inherits')
Felix Htoo
  • 874
  • 12
  • 15

1 Answers1

1

Stream isn't installed by the node_module calling it. Stream is a native module inside NodeJS. https://nodejs.org/api/stream.html

In order to use Stream you'll need to use shims. You'll need to use some combination of https://github.com/juliangruber/stream and stream-browserify, which is a browser compatible version of Stream.

Just because it's Browser friendly, doesn't make it react-native friendly. React-native runs JavaScriptCore, Apple's JS engine. It only has definitive JS attributes, while other things that you may have thought of as JS are not there because those were supplied by the browser shell. WebCrypto is missing.

After getting some JS version of Stream, you may need to use rn-nodeify, a package that helps React Native emulate a Node environment. It installs many libraries that can emulate node, rendered in JS. However it may be enough to yarn add stream, probably yarn add events next.

d36williams
  • 389
  • 1
  • 12