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

**URL:** <https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998>\
**Category:** JavaScript\
**Created:** [April 8, 2023, 4:41pm UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998 "2023-04-08T16:41:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pyprohly](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pyprohly](https://community.sendbird.com/u/Pyprohly)\
**Post date:** [April 8, 2023, 4:41pm UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998/1 "2023-04-08T16:41:29Z")

</div>

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:

```typescript
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [April 10, 2023, 5:54am UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998/2 "2023-04-10T05:54:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pyprohly](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pyprohly](https://community.sendbird.com/u/Pyprohly)\
**Post date:** [April 10, 2023, 8:32am UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998/3 "2023-04-10T08:32:01Z")

</div>

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

[https://stackblitz.com/edit/node-jpn1db](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:

```javascript
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`.

---

<div class="post-metadata">

**Author:** ![Tyler](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/tyler/32/810_2.png) [@Tyler](https://community.sendbird.com/u/Tyler)\
**Post date:** [April 10, 2023, 9:14am UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998/4 "2023-04-10T09:14:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pyprohly](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@Pyprohly](https://community.sendbird.com/u/Pyprohly)\
**Post date:** [April 10, 2023, 11:25am UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998/5 "2023-04-10T11:25:09Z")

</div>

Oh, okay. Thank you.

---

<div class="post-metadata">

**Author:** ![Hoang\_Le\_Gia](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hoang_le_gia/32/3907_2.png) [@Hoang\_Le\_Gia](https://community.sendbird.com/u/Hoang_Le_Gia)\
**Post date:** [April 19, 2023, 10:39am UTC](https://community.sendbird.com/t/getting-typeerror-cannot-read-properties-of-undefined-reading-transaction-on-sb-connect/6998/6 "2023-04-19T10:39:47Z")

</div>

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

What works for me is: `useLayoutEffect`
