0

Tying to implement Pusher Beam in react native but received the error below.

error: bundling failed: Error: Unable to resolve module crypto from PROJECT-DIRECTORY\node_modules\@pusher\push-notifications-server\utils.js: Module crypto does not exist in the Haste module map

Refer to this doc for the steps https://pusher.com/tutorials/push-notifications-android

In my App.js I put exactly the same code for the notification testing code

const PushNotifications = require('@pusher/push-notifications-server');

let pushNotifications = new PushNotifications({
  instanceId: 'YOUR_INSTANCE_ID_HERE',
  secretKey: 'YOUR_SECRET_KEY_HERE',
});

pushNotifications
  .publishToInterests(['hello'], {
    fcm: {
      notification: {
        title: 'Hello World',
        body: 'Hello!',
      },
    },
  })
  .then(publishResponse => {
    console.log('Just published:', publishResponse.publishId);
  })
  .catch(error => {
    console.log('Error:', error);
  });
Emerald
  • 864
  • 1
  • 14
  • 37
  • `crypto` is not accessible within the react-native project and That blog is not for the react-native. Do you want to integrate push notification into your react-native project? – U.A Sep 02 '20 at 02:49
  • Yes. The blog is for android and the example given is using Node.js which is what I used for react native as well. – Emerald Sep 02 '20 at 02:53
  • Please refer this https://stackoverflow.com/questions/36415157/twilio-react-native-unable-to-resolve-module-crypto – U.A Sep 02 '20 at 02:55
  • you are trying to use server SDK `@pusher/push-notifications-server` inside your react-native project – U.A Sep 02 '20 at 03:04
  • Found a workaround at here https://hackernoon.com/using-core-node-js-modules-in-react-native-apps-64acd4d07140 – Emerald Sep 02 '20 at 03:24

0 Answers0