> For the complete documentation index, see [llms.txt](https://docs.keycloakify.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keycloakify.dev/faq/it-works-in-storybook-but-not-in-keycloak.md).

# It works in Storybook but not in Keycloak

If your images appear correctly in Storybook but are broken after deploying your theme to Keycloak—or when testing with `npx keycloakify start-keycloak`—the issue is likely due to how assets are imported.

\
:octagonal\_sign: **Incorrect Import Example**

The following approach is **not** valid for importing assets in Vite or Create React App (CRA), even outside of Keycloakify:

{% code title="Component.tsx" %}

```tsx
<img src="/logo.png" />
<img src="logo.png" />
```

{% endcode %}

While this may work in some cases, it is unreliable and not officially supported (By Vite or Webpack).

Below are two correct ways to import assets in TypeScript files when using Vite or Create React App (this is not specific to Keycloakify, it's how it should be done in any project):

## 1️⃣ Using the Bundler (Recommended)

Place your logo in `src/login/assets/logo.png`, then import it like this:

{% code title="src/login/Template.tsx" %}

```tsx
import logoPngUrl from "./assets/logo.png";

<img src={logoPngUrl} />
```

{% endcode %}

This method ensures that the bundler correctly resolves and includes the asset.

## 2️⃣ Using the Public Directory

If your logo is stored in `public/img/logo.png`, use one of the following approaches:

{% tabs %}
{% tab title="Vite" %}
{% code title="src/login/Template.tsx" %}

```tsx
<img src={import.meta.env.BASE_URL + "img/logo.png"} />
```

{% endcode %}
{% endtab %}

{% tab title="Create React App / Webpack" %}
{% code title="src/login/Template.tsx" %}

```tsx
import { PUBLIC_URL } from "keycloakify/PUBLIC_URL";

<img src={PUBLIC_URL + "/img/logo.png"} />
```

{% endcode %}
{% endtab %}
{% endtabs %}

Using the public directory method is useful when assets should remain unchanged after the build process, but for most cases, bundling assets (Method 1) is the preferred approach.

***

By following these guidelines, your assets will load correctly in both Storybook and Keycloak.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keycloakify.dev/faq/it-works-in-storybook-but-not-in-keycloak.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
