ms-rest-js icon indicating copy to clipboard operation
ms-rest-js copied to clipboard

Support React Native's node environment: Module 'stream' does not exist in the Haste module map

Open syntax-e opened this issue 6 years ago • 9 comments

Is your feature request related to a problem? Please describe. My React Native app successfully leveraged ms-rest-js version 0.2.4. A recent upgrade to @azure/ms-rest-js version 1.5.3 now yields

Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) 
with error:(Unable to resolve module `stream` from 
`/Users/me/Documents/vsonline/app/node_modules/@azure/ms-rest-js/dist/msRest.node.js`: 
Module `stream` does not exist in the Haste module map

Describe the solution you'd like ms-rest-js works in React Native's node environment.

Describe alternatives you've considered none

Additional context

autorest --info:

AutoRest code generation utility [version: 2.0.4283; node: v10.9.0]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest


Showing All Installed Extensions

 Type       Extension Name                           Version      Location
 core       @microsoft.azure/autorest-core           2.0.4300     /Users/me/.autorest/@[email protected]
 extension  @microsoft.azure/autorest.modeler        2.3.51       /Users/me/.autorest/@[email protected]
 extension  @microsoft.azure/autorest.typescript     2.0.683      /Users/me/.autorest/@[email protected]
 react-native info

  React Native Environment Info:
    System:
      OS: macOS 10.14.2
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 5.32 GB / 32.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.9.0 - /usr/local/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 6.6.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 23, 24, 25, 26, 27, 28
        Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.3
        System Images: android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom_64
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5199772
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.6.3 => 16.6.3
      react-native: ^0.57.8 => 0.57.8
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-rename: 2.3.2

syntax-e avatar Jan 29 '19 21:01 syntax-e

Could this be related to this issue? If no, could you please share repro project?

kpajdzik avatar Jan 30 '19 02:01 kpajdzik

Thanks. It doesn't look related.

An example repro project: https://github.com/bearer-syntaxerror/RNAutoRestExample

The Dist/AdventuresApi/lib/ contains the autorest generated adventuresApiClientContext.js which requires @azure/ms-rest-js

@azure/ms-rest-js contains msRest.node.js which requires a number of node server libraries that aren't available in the react native node environment. A few that I've identified:

  • stream
  • os
  • xml2js which requires timers

There's a library that'll mock the standard node server libraries in react native, but it's only possible to use this library to mock node server libs within your own app and not within its dependencies like @azure/ms-rest-js: https://github.com/parshap/node-libs-react-native

Thanks for looking

syntax-e avatar Jan 31 '19 02:01 syntax-e

Thank you for the repro project! I'll take a look as soon as possible. Quick question before I dive into debugging. Would browser (msRest.browser.js) bundle work for React native? It does not include any of Node.js dependencies that are missing in the browser which include stream, os, xml2js etc.

kpajdzik avatar Jan 31 '19 02:01 kpajdzik

I gave this a try by replacing "main": "./dist/msRest.node.js" with "main": "./dist/msRest.browser.js", in node_modules/@azure/ms-rest-js/package.json which results in: DOMParser is not defined at runtime

It appears that the browser version relies on at least DOMParser that the React Native environment doesn't provide.

syntax-e avatar Jan 31 '19 18:01 syntax-e

Ok, thanks! I'll investigate this regression.

kpajdzik avatar Jan 31 '19 18:01 kpajdzik

What are the steps to reproduce it in the sample repository? npm install and npm start?

kpajdzik avatar Jan 31 '19 19:01 kpajdzik

Sure.

Follow the React Native Getting Started steps Once the React Native CLI and dependencies (node, homebrew, watchman, xcode) are installed on your system, cd into the sample repository and run: react-native run-ios which'll boot up the Xcode simulator with the React Native project running.

I haven't tested this sample repo on Windows but if you're on windows, follow the same steps, open an Android device emulator via AVD Manager or your emulator of choice, and run: react-native run-android

syntax-e avatar Jan 31 '19 20:01 syntax-e

This seems abandoned... any solution/alternative for using with RN? @kpajdzik

sceleskitribe avatar Sep 09 '20 10:09 sceleskitribe

Just an update: we are continuing our investigation in supporting React Native at https://github.com/Azure/azure-sdk-for-js/issues/5771.

jeremymeng avatar Jan 27 '21 22:01 jeremymeng