RocketChat / Rocket.Chat.js.SDK

Utility for apps and bots to interact with Rocket.Chat via DDP and/or API
MIT License
135 stars 95 forks source link

Does not work with react #97

Open martinlundin opened 5 years ago

martinlundin commented 5 years ago

I get an error when including the rocket.chat/sdk in a react app.

Steps to reproduce: yarn create react-app testchat cd testchat yarn add @rocket.chat/sdk

open App.js and add: import { driver, methodCache, api } from '@rocket.chat/sdk' Now when we run: npm start there is this error:

TypeError: Cannot read property 'map' of null
(anonymous function)
node_modules/websocket-driver/lib/websocket/http_parser.js:88
  85 |   31: 'LINK',
  86 |   32: 'UNLINK'
  87 | };
> 88 | var VERSION = (process.version || '').match(/[0-9]+/g).map(function (n) {
  89 |   return parseInt(n, 10);
  90 | });
  91 | 

What can I do to make this work together? Thanks

martinlundin commented 5 years ago

Same error when I try to import it to Vue/Nuxt.

To reproduce error: yarn create nuxt-app nuxttestchat open pages/index.vue and add: import { driver, methodCache, api } from '@rocket.chat/sdk' run: yarn run dev Same error as before with websocket http_parser.js

andrewlorenz commented 5 years ago

I had the same error too, and fixed it by updating your package.json entry for the sdk to this: "@rocket.chat/sdk": "1.0.0-alpha.30" This version is the one used by RC's own react-native client, and also worked for me when trialing with plain react.