---
url: /saas-starter/v0.10.1/guide/troubleshooting.md
---
# Troubleshooting

::: tip What this page covers
Every choice of `--Persistence`, `--Auth`, `--IncludeTests` and `--Aspire`: a label says
which options a part is for. The copy in your app's `docs/` folder has only the parts for yours.
`ApiHost` stands for your app's name.
:::

Problems people run into, by what you see. Each message here is what the app or its tools
actually print.

## Starting it

### `Failed to connect to 127.0.0.1:5432` when the API starts

```
Npgsql.NpgsqlException (0x80004005): Failed to connect to 127.0.0.1:5432
 ---> System.Net.Sockets.SocketException (111): Connection refused
```

PostgreSQL isn't running. Start it with `docker compose up -d` at the repository root, and check
it's up with `docker compose ps`. If Docker itself isn't running, `docker compose` says it can't
connect to the Docker daemon: start Docker Desktop (or the Docker service) first.

### `port is already allocated` from `docker compose up`

```
Bind for 0.0.0.0:5432 failed: port is already allocated
```

Something else is using the port, usually a PostgreSQL installed on the machine or another
project's container (`docker ps` lists those). Stop it, or give this app's container another port
in `docker-compose.yml` (`"5433:5432"`) and the connection string in
`src/ApiHost/appsettings.Development.json` to match (`Port=5433`).

::: info With accounts
Mailpit's ports, 8025 and 1025, can clash the same way.
:::

### `address already in use` for port 5133

```
System.IO.IOException: Failed to bind to address http://127.0.0.1:5133: address already in use.
```

The API is already running, often in another terminal or your IDE. Stop that one, or change
`applicationUrl` in `src/ApiHost/Properties/launchSettings.json`, and `apiUrl`, the address the
client's dev server forwards `/api` to, in `src/Client/vite.config.ts`.

::: info EF Core

### `The model for context 'AppDbContext' has pending changes`

```
System.InvalidOperationException: An error was generated for warning
'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context
'AppDbContext' has pending changes. Add a new migration before updating the database.
```

An entity or `AppDbContext` changed without a migration, so the app won't start: applying the
migrations would leave the database different from the code. Add one
([how](./how-to/add-a-migration.md)), then start it again.
:::

### `npm install` warns `EBADENGINE`, or `npm run dev` fails

```
npm warn EBADENGINE Unsupported engine { package: '@react-router/dev@...', required: { node: '>=22.22.0' } }
```

The client needs Node.js 22.22 or later (React Router's tools do). Check with `node --version`,
and update Node; with a version manager such as `nvm`, `nvm install 22` gets the latest 22.

## In development

### The page shows no data, and the dev server logs `http proxy error`

```
[vite] http proxy error: /api/todos
Error: connect ECONNREFUSED 127.0.0.1:5133
```

The client's dev server is running, but the API isn't: it forwards `/api` to
http://localhost:5133, which nothing answers (the browser gets `502 Bad Gateway`). Start the API
with `dotnet run --project src/ApiHost`, in a second terminal.

### `npm run gen:api` fails with `fetch failed`

```
ResolveError: fetch failed
  [cause]: Error: connect ECONNREFUSED 127.0.0.1:5133
```

It reads the API's OpenAPI document from the running API, at
http://localhost:5133/openapi/v1.json, which is only served in Development. Start the API, then
run it again.

::: info With accounts

### Signing in says "Confirm your email address first"

New accounts must confirm their email before they can sign in. In development, the email is in
Mailpit at http://localhost:8025. If Mailpit has nothing, it wasn't running when you signed up:
the API logs `Failed to process message ...SendEmailConfirmation` with `Connection refused`, and
tries again after 30 seconds, then 2 minutes, 10 minutes and an hour. Start it with
`docker compose up -d` and the email arrives on the next attempt; or sign up again with another
address. The demo user, `demo@example.com`, is already confirmed.
:::

### A change to an endpoint or handler doesn't show

Development generates Wolverine's code when the API starts, so a new endpoint, handler or
message type needs the API restarted. A new endpoint also needs `npm run gen:api` before the
client's types know it.

### The tests fail to start with a Docker error

The API tests start their own PostgreSQL with Testcontainers, so Docker must be running. They
don't use the database from `docker compose`, and can run while it's up.

## In production

### `MissingPreBuiltTypesException` at startup

```
Wolverine.Runtime.Handlers.MissingPreBuiltTypesException: Wolverine.Http is running in
TypeLoadMode.Static, but 72 expected pre-built HTTP endpoint type(s) could not be loaded ...
```

Production loads Wolverine's code ready-made, generated by `dotnet publish`. This is a build that
wasn't published, such as `dotnet build` output run with `ASPNETCORE_ENVIRONMENT=Production`.
Publish it (`dotnet publish src/ApiHost -c Release`, or the container image), and run the
published app ([deployment](./deployment.md)).

### `Missing '...' connection string`

::: info Marten
Set `ConnectionStrings__Marten`, usually as an environment variable: `appsettings.json` only has
the development database's.
:::

::: info EF Core
Set `ConnectionStrings__Postgres`, usually as an environment variable: `appsettings.json` only
has the development database's.
:::

::: info With accounts

### `'Jwt:SigningKey' must be at least 32 bytes`, or `is the development key`

Set a random secret of at least 32 bytes as `Jwt__SigningKey`, such as the output of
`openssl rand -base64 48`. The development key is refused outside Development, as it's in the
repository.

### `'App:ClientUrl' must be set to the app's public address`

Links in emails, and passkeys, need the app's public address: set `App__ClientUrl` to it, such as
`https://app.example.com`, with no path or query string.

### Emails aren't sent

Check the API's logs for `Failed to process message` on the email messages: the SMTP settings
(`Email__Smtp__*`) are wrong, or the server can't reach the provider. Each email is tried again
for about an hour, then kept as a failed message, which an admin can replay from the back office
once it's fixed ([configure email](./how-to/configure-email.md)).
:::

### The app works, but links and redirects use `http://`, or every visitor seems to have one address

Behind a reverse proxy (Caddy, nginx, a load balancer), set
`ASPNETCORE_FORWARDEDHEADERS_ENABLED=true`, so the app sees the original scheme and the visitor's
address. Without it, the app sees every visitor as the proxy's one address, in its logs and its
rate limits.

## Still stuck

Search the repository's issues, or open one, at
[github.com/LibreSharp/saas-starter](https://github.com/LibreSharp/saas-starter/issues), with what
you ran, what you saw, and the template version in `.saas-starter.json`.
