5

Has anybody been able to integrate PubNub with React Native?

The PubNub support team told me to use the pubnub_browserify package and it should work. However when I do require('pubnub_browserify') I get an error that the http module could not be found:

Unable to resolve module http from /Users/jfender/Documents/Workspace/KaiwaReact/node_modules/pubnub_browserify/browserify_node/pubnub.js: Invalid directory /Users/node_modules/http

Running npm install http --save doesn't change the error.

I am using Node v5.1.0, npm 3.3.12 and React Native 0.14.2.

Here is my package.json:

{
  "name": "KaiwaReact",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start"
  },
  "dependencies": {
    "eslint": "^1.10.0",
    "eslint-plugin-react": "^3.9.0",
    "parse": "^1.6.9",
    "parse-react": "^0.5.0",
    "pubnub_browserify": "^1.0.2",
    "react-native": "^0.14.2"
  }
}
Fenda
  • 1,385
  • 3
  • 14
  • 24
  • this looks suspicious... "http": "0.0.0" – Chris Geirman Nov 21 '15 at 15:08
  • @ChrisGeirman Ah, that's what I got after `npm install http --save`. Updating question to remove that line. – Fenda Nov 21 '15 at 20:10
  • Try: `npm install agentkeepalive --save` and see if that works. It says one of the dependencies is agentkeepalive... – Dair Nov 22 '15 at 01:13
  • @Dair Nope, no luck there. Although I did see `WARN engine agentkeepalive@0.2.4: wanted: {"node":"0.10.x"} (current: {"node":"5.1.0","npm":"3.3.12"})` when installing. – Fenda Nov 22 '15 at 11:16
  • Seems like there is a duplicate issue on StackOverflow: http://stackoverflow.com/questions/29371694/react-native-and-requirehttp – Fenda Nov 22 '15 at 11:37

3 Answers3

2

I was able to integrate it. I used the standard javascript package. However, I did need to modify it a bit. Mostly to remove all the references to 'window' and to 'abort'. Once I removed those, I was good to go.

eyal83
  • 3,893
  • 3
  • 19
  • 30
0

PubNub has a new Javascript SDK (v4). You should be able to add the dependency in your package.json file and import it in your code. Here's a quick example of an app that is subscribing to a PubNub channel.

https://github.com/girishd/ReactPubNub

Girish Dusane
  • 1,120
  • 4
  • 12
  • 19
-1

Please try using https://www.npmjs.com/package/pubnub (version 3.7.16) (npm install pubnub) This version works with react-native

devendram
  • 257
  • 1
  • 5
  • @davendram I've run `npm install pubnub --save` and adding `var PubNub = require("pubnub");` to my index JS file and it returns `Unable to resolve module pubnub`. – Fenda Nov 23 '15 at 11:59
  • @davendram I downgraded to Node v4.2.2 and npm 2.14.7 to avoid using the flat modules structure to see if that helped. No luck there either, still getting the same error. – Fenda Nov 23 '15 at 12:46
  • We are working on new content to assist here. Stay tuned for new response. – Craig Conover Aug 12 '16 at 18:49
  • Installed pubnub but there's a dependency on `crypto` and I'm stuck due to that. Noted at https://github.com/girishd/ReactPubNub/issues/1 – coder.in.me Dec 08 '16 at 09:57