> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kleap.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Error Reference

> Common error messages and how to fix them

A guide to common error messages and their solutions.

## Build Errors

### Module not found

```
Error: Cannot find module '@/components/Button'
```

**Cause**: The imported file doesn't exist or path is wrong.

**Fix**:

```
The import '@/components/Button' can't be found.
Can you check if the file exists and fix the import path?
```

***

### Unexpected token

```
SyntaxError: Unexpected token '<'
```

**Cause**: JavaScript syntax error, often in JSX.

**Fix**:

```
Getting a syntax error "Unexpected token".
Can you find and fix the syntax issue?
```

***

### Type error

```
Type 'string' is not assignable to type 'number'
```

**Cause**: TypeScript type mismatch.

**Fix**:

```
Getting this type error: [full error message]
Can you fix the type issue?
```

***

### Export not found

```
Attempted import error: 'Button' is not exported from './components'
```

**Cause**: Component exists but isn't exported.

**Fix**:

```
The 'Button' component isn't exported properly.
Can you add the export to the component file?
```

## Runtime Errors

### Cannot read properties of undefined

```
TypeError: Cannot read properties of undefined (reading 'map')
```

**Cause**: Trying to use a method on undefined/null value.

**Fix**:

```
Getting "Cannot read properties of undefined" when mapping over data.
Can you add a check for undefined and handle the empty state?
```

***

### X is not a function

```
TypeError: response.json is not a function
```

**Cause**: Variable isn't what you expect.

**Fix**:

```
Getting "[x] is not a function" error.
Can you check the variable type and fix the function call?
```

***

### Network error

```
TypeError: Failed to fetch
```

**Cause**: API request failed (network, CORS, or server error).

**Fix**:

```
API fetch is failing with a network error.
Can you check the API endpoint and error handling?
```

## React Island Errors

These happen inside interactive React components (islands) on your Astro site.

### Hydration mismatch

```
Hydration failed because the initial UI does not match what was rendered on the server
```

**Cause**: The static HTML and the hydrated island render different content.

**Fix**:

```
Getting a hydration mismatch error.
Can you fix the component to render the same on server and client?
```

Common causes:

* Using `Date.now()` or `Math.random()` directly
* Accessing `window` or `localStorage` without checks
* Conditional rendering based on browser-only values

***

### Invalid hook call

```
Invalid hook call. Hooks can only be called inside of the body of a function component
```

**Cause**: Hook used incorrectly.

**Fix**:

```
Getting "Invalid hook call" error.
Can you check that hooks are only used in function components and not inside conditions or loops?
```

***

### Too many re-renders

```
Error: Too many re-renders. React limits the number of renders
```

**Cause**: Component is in infinite render loop.

**Fix**:

```
Getting "Too many re-renders" error.
Can you find and fix the infinite loop in the component?
```

Usually caused by:

* Calling `setState` directly in render
* Missing dependency array in `useEffect`
* State update triggering another state update

## Database Errors

### Permission denied on a row

```
This action isn't allowed for the current user on table "posts"
```

**Cause**: Data is scoped per user, and this operation isn't permitted for the signed-in user.

**Fix**:

```
Getting a permission error when [inserting/updating/deleting] data.
Can you check that the data rules let the right users read and write this table?
```

***

### Foreign key violation

```
insert or update on table "posts" violates foreign key constraint
```

**Cause**: Referenced record doesn't exist.

**Fix**:

```
Getting foreign key violation error.
The referenced [table] record doesn't exist.
Can you fix the query or create the referenced record first?
```

***

### Duplicate key

```
duplicate key value violates unique constraint
```

**Cause**: Trying to insert duplicate value in unique column.

**Fix**:

```
Getting duplicate key error.
Can you add a check for existing records or use upsert?
```

## Authentication Errors

### Session not found

```
Auth session missing — no signed-in user
```

**Cause**: User not logged in or session expired.

**Fix**:

```
Getting "session missing" error.
Can you add authentication check and redirect to login if not authenticated?
```

***

### Invalid login credentials

```
Invalid login credentials
```

**Cause**: Wrong email or password.

**Fix**: This is expected for wrong credentials. Ensure your error handling shows a user-friendly message.

## Environment Variable Errors

### Missing environment variable

```
Error: Missing environment variable: PUBLIC_API_URL
```

**Cause**: Required variable not set. (In Astro, browser-exposed variables are
prefixed with `PUBLIC_`.)

**Fix**:

1. Go to Settings > Environment
2. Add the missing variable
3. Redeploy if in production

## Quick Reference Table

| Error Contains        | Likely Cause           | Quick Fix                |
| --------------------- | ---------------------- | ------------------------ |
| `Cannot find module`  | Wrong import           | Check file path          |
| `undefined`           | Missing data           | Add null check           |
| `not a function`      | Wrong variable type    | Check variable           |
| `Hydration`           | Server/client mismatch | Fix SSR                  |
| `Invalid hook`        | Hook misuse            | Check hook rules         |
| `Too many re-renders` | Infinite loop          | Fix useEffect/setState   |
| `not allowed`         | Per-user data rule     | Check table access rules |
| `Failed to fetch`     | Network/API issue      | Check endpoint           |
| `PUBLIC_`             | Env var missing        | Add to settings          |

## Getting More Help

If an error isn't listed here:

1. **Copy the full error message**
2. **Paste it to Kleap AI** with context about what you were doing
3. **Check browser console** for additional details

<Card title="Troubleshooting Guide" icon="wrench" href="/tips/troubleshooting">
  Step-by-step solutions to common problems
</Card>
