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

react-native Unable to resolve module path: /node_modules/rhea/lib/connection.js #25082

Closed
4 of 6 tasks
MykhailoButkevych-PE opened this issue Mar 3, 2023 · 5 comments
Closed
4 of 6 tasks
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback Workflow: More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus

Comments

@MykhailoButkevych-PE
Copy link

MykhailoButkevych-PE commented Mar 3, 2023

  • Package Name: @azure/service-bus
  • Package Version: 7.8.0
  • Operating system: macos 13.0.1
  • nodejs
    • version: 18.12.1
  • react-native
    • name/version: 0.71.3
  • typescript
    • version: 4.8.4
  • Is the bug related to documentation in

Describe the bug
Creating new instance of ServiceBusClient, for example: const serviceBusClient = new ServiceBusClient( 'Endpoint=sb://my-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123xyz456', );

throws error:

error: Error: Unable to resolve module path from /Users/me/AwesomeProject/node_modules/rhea/lib/connection.js: path could not be found within the project or in these directories:
node_modules/rhea/node_modules
node_modules
27 | var fs = require('fs');
28 | var os = require('os');
29 | var path = require('path');

To Reproduce
Steps to reproduce the behavior:

  1. Create new react-native app: npx react-native@latest init AwesomeProject
  2. Install package: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus/#install-the-package
  3. Configure ts: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus/#configure-typescript
  4. Import & create serviceBusClient instance in App.tsx, for example: const serviceBusClient = new ServiceBusClient( 'Endpoint=sb://my-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123xyz456', );
  5. Error appears.

Expected behavior
There shouldn't be an issue with resolving module path.

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 3, 2023
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 3, 2023
@xirzec xirzec added Client This issue points to a problem in the data-plane of the library. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Mar 3, 2023
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Mar 3, 2023
@jeremymeng
Copy link
Member

Thanks for reporting this @MykhailoButkevych-PE! path is one of the NodeJS module that rhea depends on so we need to provide a polyfill for it when running in a non-NodeJS environment. I will take a look.

@jeremymeng
Copy link
Member

@MykhailoButkevych-PE please check out the steps in our react-native sample for AMQP messaging SDKs (Event Hubs and Service Bus)
https://github.com/Azure/azure-sdk-for-js/blob/main/samples/frameworks/react-native-expo/ts/messaging/README.md

Even though the sample is using Expo, I just tried and found that the same steps can also be applied to a project created by npx react-native@latest init

@jeremymeng jeremymeng added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Mar 6, 2023
@jeremymeng
Copy link
Member

The sample linked above uses node-libs-react-native package for polyfills. For our Service Bus SDK, only four polyfills are actually used:

  • buffer
  • path-browserify
  • process
  • os-browserfify

so the steps to add them are:

  • yarn add buffer os-browserify path-browserify process
  • metro.config.js
module.exports = {
  resolver: {
    extraNodeModules: {
      buffer: require.resolve('buffer/'),
      path: require.resolve('path-browserify'),
      process: require.resolve('process/browser.js'),
      os: require.resolve('os-browserify/browser.js'),
    },
  },
  // ...
}
  • App.tsx before importing Azure Service Bus SDK
global.Buffer = require('buffer').Buffer;
global.process = require('process');

import 'react-native-get-random-values';

@MykhailoButkevych-PE
Copy link
Author

@jeremymeng Thanks for help, now it's working!

@jeremymeng
Copy link
Member

@MykhailoButkevych-PE Glad to hear!

@github-actions github-actions bot locked and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-author-feedback Workflow: More information is needed from author to address the issue. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus
Projects
None yet
Development

No branches or pull requests

3 participants