> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-agent-native-development.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Troubleshooting

> Fix CometChat JavaScript SDK issues with initialization, login, WebSocket events, SSR errors, and SDK method failures.

Find solutions to common issues when building with the CometChat JavaScript SDK.

<Accordion title="AI Integration Quick Reference">
  | Issue | Fix |
  | - | - |
  | `init()` fails | Verify App ID and Region from [Dashboard](https://app.cometchat.com) |
  | Login fails with "UID not found" | Create user via Dashboard or REST API first |
  | SDK methods fail | Ensure `init()` completes before calling other methods |
  | No real-time events | Check WebSocket connection, verify listeners registered |
  | SSR errors | Use dynamic imports or `useEffect` for client-side only |
</Accordion>

***

## Initialization & Authentication

| Symptom | Cause | Fix |
| - | - | - |
| `init()` fails with "App ID not found" | Invalid App ID or Region | Verify credentials in [Dashboard](https://app.cometchat.com) → API & Auth Keys |
| `init()` fails silently | Missing credentials | Double-check App ID and Region are strings, not undefined |
| "CometChat not initialized" | `init()` not awaited | Ensure `init()` resolves before calling other methods |
| Login fails with "UID not found" | User doesn't exist | Create user via [Dashboard](https://app.cometchat.com) or [REST API](https://api-explorer.cometchat.com/reference/creates-user) |
| Login fails with "Auth Key is not valid" | Wrong Auth Key | Verify Auth Key in Dashboard. Don't confuse with REST API Key |
| `getLoggedinUser()` returns null | Session cleared or `init()` not called | Call `init()` on every app load before checking session |
| User appears offline after login | Presence not configured | Use `subscribePresenceForAllUsers()` in `AppSettingsBuilder` |

***

## Messaging

| Symptom | Cause | Fix |
| - | - | - |
| `sendMessage()` fails | Not logged in or invalid receiver | Ensure `login()` completes. Verify receiver UID/GUID exists |
| Messages sent but not received | Listener not registered | Register `addMessageListener()` with `onTextMessageReceived` |
| Duplicate messages | Multiple listeners | Use unique listener IDs. Remove old listeners first |
| Wrong conversation | Wrong receiver type | Use `RECEIVER_TYPE.USER` for 1:1, `RECEIVER_TYPE.GROUP` for groups |
| Media upload fails | File too large or unsupported | Check limits. Supported: PNG, JPG, GIF, MP4, MP3, WAV |
| Metadata not appearing | Set after send | Call `setMetadata()` before the send method |
| Pagination not working | New request object | Reuse the same `MessagesRequest` for `fetchPrevious()`/`fetchNext()` |
| Thread replies in main chat | Missing filter | Add `.hideReplies(true)` to `MessagesRequestBuilder` |
| Deleted messages showing | Missing filter | Add `.hideDeletedMessages(true)` |

***

## Groups

| Symptom | Cause | Fix |
| - | - | - |
| Cannot join group | Invalid GUID | Verify GUID. Create group first if needed |
| Cannot send to group | Not a member | Join group first with `joinGroup()` |
| Cannot kick/ban members | Insufficient scope | Only admins and moderators can kick/ban |
| Can't join private group | Requires invite | Private groups require admin to add you |
| Owner can't leave | Ownership not transferred | Call `transferGroupOwnership()` first |
| Password join fails | Wrong password | Pass correct password as third parameter |
| `fetchNext()` returns same results | New request object | Reuse the same `GroupsRequest` instance |
| Scope filter returns nothing | Invalid strings | Use `"admin"`, `"moderator"`, `"participant"` |
| Status filter not working | Wrong constant | Use `CometChat.USER_STATUS.ONLINE`/`OFFLINE` |
| Cannot demote admin | Not owner | Only group owner can demote admins |
| Kicked user can still see group | Kick vs ban | Use `banGroupMember()` to prevent rejoining |

***

## Calling

| Symptom | Cause | Fix |
| - | - | - |
| Calls SDK not found | Not installed | Run `npm install @cometchat/calls-sdk-javascript` |
| No audio/video | Permissions denied | Check browser permissions for camera/microphone |
| Call not connecting | Session ID mismatch | Verify both participants use same session ID |
| One-way audio | Firewall blocking WebRTC | Check network config. Corporate networks may block WebRTC |
| Incoming call not showing | Listener not registered | Register `addCallListener()` at app root level |
| Call ended event not received | Wrong callback | Use `onCallEndedMessageReceived` in `CallListener` for call-end messages, `onCallEnded` in `OngoingCallListener` for session events |
| Black screen after joining | Element not visible | Ensure HTML element has proper dimensions |
| CSS changes not applying | Specificity issue | Try adding `!important` |
| Styles only work in one mode | Mode-specific classes | Test in `DEFAULT`, `TILE`, and `SPOTLIGHT` modes |

***

## WebSocket & Connection

| Symptom | Cause | Fix |
| - | - | - |
| Real-time events not received | WebSocket disconnected | Check `getConnectionStatus()`. Reconnect if needed |
| WebSocket fails | Firewall blocking | Check network config. Corporate firewalls may block WebSocket |
| Connection drops frequently | Network instability | Use `addConnectionListener()` to monitor and reconnect |
| Stuck in "connecting" | Network or config issue | Verify network, `appId`, and `region` |
| No events after login | Auto-connect disabled | Call `CometChat.connect()` manually if `autoEstablishSocketConnection(false)` |
| `connect()` doesn't work | Not logged in | Ensure user is logged in first |

***

## Listeners

| Symptom | Cause | Fix |
| - | - | - |
| Events not firing | Registered before init | Register after `init()` and `login()` complete |
| Duplicate events | Multiple listeners | Remove old listeners before adding new ones |
| Missing events after navigation | Listeners removed | Re-register when new component mounts |
| Receipt events not triggering | Receipts not sent | Call `markAsDelivered()`/`markAsRead()` explicitly |

***

## Typing, Receipts & Reactions

| Symptom | Cause | Fix |
| - | - | - |
| Typing indicator stuck | `endTyping()` not called | Call on send, blur, or after 3-5s timeout |
| Double-tick not showing | `markAsDelivered()` not called | Call on message fetch and real-time receive |
| Group receipts missing | Feature not enabled | Enable "Enhanced Messaging Status" in Dashboard |
| `onMessagesDeliveredToAll`/`onMessagesReadByAll` not firing | Not registered | Register these callbacks in `MessageListener` for group-level receipt events |
| Reaction not appearing | UI not synced | Call `updateMessageWithReactionInfo()` on events |
| Duplicate reactions | No check before adding | Use `getReactedByMe()` first |

***

## AI Features

| Symptom | Cause | Fix |
| - | - | - |
| AI features not appearing | Not enabled | Enable in [Dashboard](https://app.cometchat.com) → AI Features |
| AI Agents not responding | Not configured | Configure Agent in Dashboard. Agents only respond to text |
| `onAIAssistantEventReceived` not firing | Listener not registered | Register `AIAssistantListener` after login |
| Moderation always PENDING | Rules not configured | Configure rules in Dashboard → Moderation → Rules |
| Agentic messages not arriving | Wrong listener | Use `MessageListener` with `onAIAssistantMessageReceived` |

***

## SSR / Framework-Specific

| Symptom | Cause | Fix |
| - | - | - |
| "window is not defined" | SDK accessed during SSR | Use dynamic imports or `useEffect` |
| Next.js SSR error | Server render | Use `await import('@cometchat/chat-sdk-javascript')` |
| Nuxt "document is not defined" | Server render | Import in `mounted()` lifecycle hook |
| React Native errors | Wrong SDK | Use `@cometchat/chat-sdk-react-native` |

***

## Upgrading from V3

| Symptom | Cause | Fix |
| - | - | - |
| "Module not found" | Old import paths | Replace `@cometchat-pro/chat` with `@cometchat/chat-sdk-javascript` |
| Calls SDK not working | Wrong package | Use `@cometchat/calls-sdk-javascript` |
| Both versions installed | Package conflict | Remove v3 package completely |

***

## Error Codes

For the complete SDK error code reference, see [Error Codes](/sdk/javascript/error-codes). Common errors you'll encounter:

| Code | Description | Resolution |
| - | - | - |
| `ERR_UID_NOT_FOUND` | User doesn't exist | Create user via Dashboard or REST API |
| `MISSING_PARAMETERS` | Required parameter not provided | Check method signature and pass all required params |
| `NOT_INITIALIZED` | `init()` not called | Call `CometChat.init()` before any other method |
| `USER_NOT_LOGGED_IN` | No active session | Call `login()` first |
| `ERR_GUID_NOT_FOUND` | Group doesn't exist | Create group or verify GUID |
| `ERR_NOT_A_MEMBER` | Not a group member | Join group first |
| `TOO_MANY_REQUEST` | Rate limit exceeded | See [Rate Limits](/sdk/javascript/rate-limits) |
| `FAILED_TO_FETCH` | Network issue | Check internet connection and API endpoint |
| `NO_WEBSOCKET_CONNECTION` | WebSocket disconnected | Check connection status, wait for reconnect |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Setup SDK" icon="gear" href="/sdk/javascript/setup-sdk">
    Installation and initialization guide
  </Card>

  <Card title="Best Practices" icon="check" href="/sdk/javascript/best-practices">
    Recommended patterns and practices
  </Card>

  <Card title="Error Codes" icon="triangle-exclamation" href="/sdk/javascript/error-codes">
    Complete SDK error code reference
  </Card>

  <Card title="AI Integration" icon="robot" href="/sdk/javascript/ai-agents">
    AI Agents, Moderation, and Copilot
  </Card>

  <Card title="Support" icon="headset" href="https://help.cometchat.com/hc/en-us/requests/new">
    Open a support ticket
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.