Skip to content

[Bug]: React Native - Unable to resolve module stream #1983

@berg-dee

Description

@berg-dee

MQTTjs Version

5.11.0

Broker

mosquitto

Environment

Browser

Description

Hi,

I've been using this library on version 5.10.4 in a react native environment without any issues for a while, I've followed the instructions to add url and buffer since they are not available in the react native environment out of the box. But since version 5.11.0 it's having issues with stream

 (NOBRIDGE) ERROR  [Error: undefined Unable to resolve module stream from /Users/bergdee/Documents/code/app/node_modules/mqtt/build/lib/connect/socks.js: stream could not be found within the project or in these directories:
  node_modules/mqtt/node_modules
  node_modules
  39 | exports.default = openSocks;
  40 | const debug_1 = __importDefault(require("debug"));
> 41 | const stream_1 = require("stream");
     |                           ^
  42 | const socks_1 = require("socks");
  43 | const dns = __importStar(require("dns"));
  44 | const util_1 = require("util");]
iOS Bundling failed 1470ms node_modules/expo-router/entry.js (1 module)
The package at "node_modules/mqtt/build/lib/connect/socks.js" attempted to import the Node standard library module "stream".
It failed because the native React runtime does not include the Node standard library.
Learn more: https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries

If I try to resolve this by installing stream npm i stream, I'm followed by the next issue

The package at "node_modules/mqtt/build/lib/connect/socks.js" attempted to import the Node standard library module "dns".

Does anyone know how to solve/polyfill this for react-native?

Minimal Reproduction

Install 5.11.0 in a react native environment

Debug logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions