🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Components & Islands••By Komal Nakrani

Fix: No Import Found for Component in Astro

Fix Astro's 'No import found for component' error: a component with a client: directive must be statically imported in the same .astro file. Causes and fixes.

#Astro#Errors#Islands#Client Directives

Astro throws “No import found for component” when a component with a client:* directive wasn’t imported with a static import statement in the same .astro file. To hydrate an island, Astro’s compiler has to know which file the component comes from, and it only learns that from a top-level import in the frontmatter. Import the component directly and the error disappears.

Key Takeaways

  • Any component rendered with client:load, client:idle, client:visible, client:media or client:only needs a static import in that file.
  • Components picked at runtime (from an object, a prop or a variable) can’t be hydrated this way.
  • Server-only components (no client:*) don’t need this, so the error only appears on islands.
  • Wrap dynamic choices in a small .astro component that imports each option.

The exact error

No import found for component.

Could not render `Widget`. No matching import has been found for `Widget`.

Hint: Please make sure the component is properly imported.

The name in backticks is the tag you used in the template.

What causes it

For each island, Astro records the component’s import path and export name at compile time, then writes them into the page so the browser knows what JavaScript to load. If the tag doesn’t trace back to an import in the frontmatter, that information is missing. Common triggers:

---
// src/pages/index.astro  (broken)
import * as widgets from '../components/widgets';

const Widget = widgets[Astro.props.kind]; // chosen at runtime
const { Chart } = Astro.props;            // passed in as a prop
---
<Widget client:visible />
<Chart client:load />

The fix

Import each island component by name at the top of the file that renders it:

---
// src/pages/index.astro
import Counter from '../components/Counter.jsx';
import Chart from '../components/Chart.jsx';
---
<Counter client:load />
<Chart client:visible />

The import must be in the same file as the tag with the client:* directive. Importing it in a layout and rendering it in a page won’t work.

Choosing a component at runtime

If you need to pick between islands based on data, move the choice into a small component that imports every option statically:

---
// src/components/WidgetSwitch.astro
import Map from './Map.jsx';
import Chart from './Chart.jsx';

const { kind, ...props } = Astro.props;
---
{kind === 'map' && <Map client:visible {...props} />}
{kind === 'chart' && <Chart client:visible {...props} />}

Each branch now has a known import, and only the branch that renders ships JavaScript. Alternatively, hydrate a single wrapper component written in your UI framework and let it switch between children inside the framework, where runtime selection is normal.

If the component doesn’t need to be interactive, drop the client:* directive. Astro renders it to HTML on the server and needs no hydration data.

For choosing the right directive, see which client directive to use, and lazy-load islands with client:visible for the most common one. A related error is no matching renderer, which means the framework integration is missing. Our folder structure docs show where components live in a theme, and Komal themes in the theme catalog keep islands to a minimum by default. The Astro error reference has the official entry.

FAQ

Why does my component work without client:load but fail with it?

Without a directive, Astro only renders the component on the server, which works with any value. With a directive, Astro also needs the component’s import path for the browser, which requires a static import.

Can I hydrate a component passed as a prop in Astro?

Not directly. Import the component in the file that adds the client:* directive, or pass data instead and let that file decide which imported component to render.

Do Astro components need an import for client directives?

Astro components (.astro files) can’t take a client:* directive at all, because they have no client-side runtime. Only framework components, such as React, Vue, Svelte, Preact or Solid, are hydrated, and each needs a static import.