Getting `TypeError: Cannot read properties of undefined (reading 'transaction')` on `sb.connect()`

Coming from the v3 SDK, I’m struggling to get a very basic script working with the Sendbird Chat v4 SDK for JavaScript. The sb.connect() line seems to always throw a TypeError.

Code:

import SendbirdChat from '@sendbird/chat';
import {
    GroupChannelModule,
    type SendbirdGroupChat,
} from '@sendbird/chat/groupChannel';

const APP_ID = '...';
const USER_ID = '...';

(async () => {
    var sb = SendbirdChat.init({
        appId: APP_ID,
        modules: [new GroupChannelModule()],
    }) as SendbirdGroupChat;

    const user = await sb.connect(USER_ID);
    console.log(user);
})();

Traceback:

TypeError: Cannot read properties of undefined (reading 'transaction')
    at t._getObjectStore (file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-8a2944ef.js:1:88684)
    at file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-8a2944ef.js:1:89316
    at new Promise (<anonymous>)
    at t.<anonymous> (file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-8a2944ef.js:1:89281)
    at file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-d526f35e.js:1:2257
    at Object.next (file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-d526f35e.js:1:2362)
    at file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-d526f35e.js:1:1278
    at new Promise (<anonymous>)
    at i (file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-d526f35e.js:1:1023)
    at t._getRaw (file:///Users/danpro/Desktop/sb/node_modules/@sendbird/chat/__bundle-8a2944ef.js:1:89178)

Node.js v19.8.1

What could be the cause of this error?

Hello @Pyprohly,

Welcome to the Sendbird Community.

Can you provide an example of this using something like stackblitz or codesandbox? I’m unable to reproduce this behavior.

I tried it on StackBlitz and I’m getting an identical error.

https://stackblitz.com/edit/node-jpn1db

  1. Create new project with “Node.js - Blank project”.

  2. Replace the code in the index.js file with this code:

import SendbirdChat from '@sendbird/chat';
import { GroupChannelModule } from '@sendbird/chat/groupChannel';

const APP_ID = '...';
const USER_ID = '...';

(async () => {
  var sb = SendbirdChat.init({
    appId: APP_ID,
    modules: [new GroupChannelModule()],
  });

  const user = await sb.connect(USER_ID);
  console.log(user);
})();
  1. Add "type": "module", to the package.json file.

  2. Run npm install @sendbird/chat.

  3. Run node index.js.

Ah, I think the issue is that you’re using this in a node environment. Due to the incredible number of polyfills required, we removed support for node in V4. As a result, you’ll need to use it in a browser environment.

Oh, okay. Thank you.

Wait hour to find a workaround.
initially I was using useEffect and get the same error.

What works for me is: useLayoutEffect