Rocket.Chat.js.SDK icon indicating copy to clipboard operation
Rocket.Chat.js.SDK copied to clipboard

Does not work with react

Open martinlundin opened this issue 6 years ago • 2 comments

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 avatar Sep 20 '19 09:09 martinlundin

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

martinlundin avatar Sep 20 '19 14:09 martinlundin

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.

andrewlorenz avatar Oct 14 '19 21:10 andrewlorenz