React-native-render-html: Unable to resolve module `stream`

Created on 27 Mar 2019  路  21Comments  路  Source: meliorence/react-native-render-html

Is this a bug report or a feature request?

Bug reportt

Have you read the guidelines regarding bug report?

no

Have you read the documentation in its entirety?

yes

Have you made sure that your issue hasn't already been reported/solved?

yes

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

I have only checked on Android

Is the bug reproductible in a production environment (not a debug one)?

debug doesn't run

Have you been able to reproduce the bug in the provided example?

no

Environment

Environment:
React: ^16.6.3
React native: ^0.59.2
react-native-render-html: ^4.1.2

Target Platform:
Android (6.0)
iOS (10.3)

Hi , I have updated react-native version to the latest. and I am trying to run:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

at first I got the error: ViewStylesPropTypes but I guess that got resolved when I updated to 4.1.2
And now I get this error:

error Unable to resolve module `stream` from `/Users/yasir/Projects/jobsaf/node_modules/htmlparser2/lib/WritableStream.js`: Module `stream` does not exist in the Haste module map
bug FAQ candidate

Most helpful comment

if use "htmlparser2": "^4.0.0"锛孶nable to resolve module stream
must use "htmlparser2": "^3.10.1"

All 21 comments

Hi,
delete your node_modules folder and re-install it. You should be good to go.

if use "htmlparser2": "^4.0.0"锛孶nable to resolve module stream
must use "htmlparser2": "^3.10.1"

How to do that? How to downgrade htmlparser2?

is it solved????
i had same problem when i upgrade to 4.2.0

Working on it. related: fb55/htmlparser2#499

I tried to reproduce the issue with a blank new project. Here are the steps:

react-native init test
cd test
npm i react-native-render-html react-native-webview

Then, add import HTML from 'react-native-render-html' in your App.js file.
Run:

npm start & sleep 3; npm run android

And the program runs with no exception. I bet your issue is related to a broken cache, either in metro, or in node_modules.
You could also check in package-lock.json which version of htmlparser2 is retained. And/or delete package-lock.json, delete node_modules and reinstall.

Please ignore my previous comment, because I didn't try the production build. The version 4.0 of htmlparser2 removed their own implementation of Stream in favor of node stream, which exactly reflects the error you are having @yasir-netlinks. The upgrade to 4.0 was caused by this commit 6ef90ee4bbb10d6894bb20713188c2bf4d5bc90c, but unfortunately we don't have much information on what exactly this commit aim was. @Ryabchikus can you offer some insight?

htmlparser2 explicitly targets node ecosystem, and thus understandably doesn't guarantee compatibility with react-native. We will have to revert back to 3.X, and consider another library in the future, or start a fork of this library. I'll wait for Serguey feedback to understand the implications of reverting, and publish a fix soon.

@jsamr more information of this commit here: https://github.com/archriss/react-native-render-html/pull/318
Maybe I didn't understand the question?

@Ryabchikus Well, the commit message claims to fix some issues, but doesn't really explain which issues were resolved by version 4 of htmlparser2, although I understand with the PR that would be related to iframes. That would help if you could tell us :-)

I went a step further in the investigation. I created a test automation script to run this command for every react native version configured:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output .build/rn$version.js --assets-dest .build/android

This command is run in a project requiring and using the latest version of react-native-render-html. So I tested the versions 0.59.2 and 0.63.1 of React Native, and it passed. Seemingly, the steam module is not resolved by the metro bundler and thus we can keep the version 4.x of htmlparser2. The project is here: https://github.com/jsamr/react-native-render-html-issue-244

@yasir-netlinks @MrLaibin @brambang @rukmanary and anybody experiencing the issue, I need your help.
Clone the test repository:

git clone https://github.com/jsamr/react-native-render-html-issue-244.git

Then, you need to change the files contained in the template dir. These files will be copied for each project testing a particular version of react native, in the versions directory. If you need a specific version, add it to config.sh. Of course you don't need to reproduce your full project, just select enough files to reproduce the error. To run the tests, follow instructions on the README.

When you have managed to reproduce, please share your template folder in an archive, or print a single-file reproduction here, or share a repository to help me and others investigate.

After reading this commit bb63adbcffd1ea1c38b24fb543d3e374c156b2b2, I realized that in version 3.10.0 of htmlparser2, the stream require was replaced by readable-stream, which was provided as a direct dependency. But version 4 reverted that change when migrating to typescript. See my ticket here https://github.com/fb55/htmlparser2/issues/517.

I believe the impossibility to reproduce this issue from scratch (cf my previous comment) is caused by the metro bundler, which might in some instances strip the file requiring the stream module in some sort of dependency graph optimization, and in other instances it leaves it there.

I'm waiting for @fb55 to see if he can offer a workaround for react native users, and if that is impossible I will revert the commit 6ef90ee4bbb10d6894bb20713188c2bf4d5bc90c ASAP.

This issue will be fixed in version 4.2.2.
A pre-release is already available if you want this fix now, see #385.

If you encounter similar issues (unable to resolve XXX), check this: https://stackoverflow.com/a/63111913/2779871

That error is come back in 4.2.3 @jsamr

@felansu Have you tried the procedures described in the stackoverflow issue that I posted?

Yes, i always do that,

the exactly error is:

error: Error: Unable to resolve module ./MultiplexHandler from node_modules/htmlparser2/lib/CollectingHandler.js:

None of these files exist:

  • node_modules/htmlparser2/lib/MultiplexHandler(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.svg|.native.svg|.svg)
  • node_modules/htmlparser2/lib/MultiplexHandler/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.svg|.native.svg|.svg)
    at ModuleResolver.resolveDependency (/Users/felansu/cloq/orion/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (/Users/felansu/cloq/orion/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (/Users/felansu/cloq/orion/node_modules/metro/src/node-haste/DependencyGraph.js:287:16)
    at Object.resolve (/Users/felansu/cloq/orion/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at /Users/felansu/cloq/orion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:434:31
    at Array.map ()
    at resolveDependencies (/Users/felansu/cloq/orion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:431:18)
    at /Users/felansu/cloq/orion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next ()
    at asyncGeneratorStep (/Users/felansu/cloq/orion/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)

And yes, i always close metro, remove node_modules, run react reseting cache, etc...

@felansu Please provide a mcve and I'll be happy to help investigate, or a tarball of your project by mail (In which case I swear to just investigate and delete the code afterwards) .

I am really willing to help, but if no-one shares a reproduction, or send me an archive privately, I just can't. My email address is visible on my github profile, so off you go!

Sorry, i dont have free time for make a project for test that bug, i only report last version crash with that error.

I use minifyEnabled true in app build.gradle, maybe that is related

I am going to lock this conversation now so that the current solution is visible to visitors. If anybody is facing a similar issue, and has tried the workarounds posted here https://stackoverflow.com/a/63111913/2779871, including removing the package lockfile, I suggest, considering the difficulty to reproduce this error in new projects, either one of these actions:

  • Send me an email with an archive containing the project in which the error is raised so that I privately inspect (my email address is visible in my GH profile);
  • Send me a reproduction, either by mail or on our Discord #support channel; I believe a reproduction could work if you use the same set of dependencies; so copy & paste the package.json and package-lock.json (or similar lock files depending on your package manager).
Was this page helpful?
0 / 5 - 0 ratings

Related issues

presencewebdesign picture presencewebdesign  路  7Comments

diamanthaxhimusa picture diamanthaxhimusa  路  7Comments

f-roland picture f-roland  路  3Comments

duansiyu picture duansiyu  路  4Comments

aiavci picture aiavci  路  3Comments