Rocket.Chat.js.SDK
Rocket.Chat.js.SDK copied to clipboard
Does not work with react
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
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
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.