Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
syntax-e opened this issue Jan 29, 2019 · 9 comments

Comments

@syntax-e
Copy link

syntax-e commented Jan 29, 2019

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/@microsoft.azure_autorest-core@2.0.4300
 extension  @microsoft.azure/autorest.modeler        2.3.51       /Users/me/.autorest/@microsoft.azure_autorest.modeler@2.3.51
 extension  @microsoft.azure/autorest.typescript     2.0.683      /Users/me/.autorest/@microsoft.azure_autorest.typescript@2.0.683
 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
@kpajdzik
Copy link
Contributor

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

@kpajdzik kpajdzik self-assigned this Jan 30, 2019
@syntax-e
Copy link
Author

syntax-e commented Jan 31, 2019

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

@kpajdzik
Copy link
Contributor

kpajdzik commented Jan 31, 2019

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.

@syntax-e
Copy link
Author

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.

@kpajdzik
Copy link
Contributor

Ok, thanks! I'll investigate this regression.

@kpajdzik
Copy link
Contributor

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

@syntax-e
Copy link
Author

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

@kpajdzik kpajdzik removed their assignment Aug 5, 2019
@sceleskitribe
Copy link

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

@jeremymeng
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants