Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

How to Fix LocalImageUsedWrongly: src Cannot Be a String Filepath

Astro says the Image src parameter must be an imported image or a URL, it cannot be a string filepath? Import the picture first. Tested on Astro 7.4.

Tested on Astro 7.4

Cover image for How to Fix LocalImageUsedWrongly: src Cannot Be a String Filepath
In this guide
  1. Why it happens
  2. How to fix it
  3. Still stuck?
  4. Where to go next
  5. Frequently asked questions

You get LocalImageUsedWrongly when you give Astro’s <Image /> a typed path, like src="../assets/photo.png". Astro can’t use a path in quotes. Import the picture at the top of the file instead. Then pass it in with curly brackets, like src={photo}.

Why it happens

Astro’s <Image /> does smart work. It finds how big the picture is. It makes a small, fast copy. To do that, it has to read the file when it builds your site.

Astro can only read pictures you import. A path in quotes is just words. Astro does not know it points to a file.

We made this page in a fresh Astro 7.4 project. The file is really there:

---
import { Image } from 'astro:assets';
---
<h1>About me</h1>
<Image src="../assets/astro.svg" alt="The Astro logo" />

Then we ran the build. Here is the error, with the long file paths cut out:

Terminal
$ npm run build
[LocalImageUsedWrongly] `Image`'s and `getImage`'s `src` parameter must be an imported image or a URL, it cannot be a string filepath. Received `../assets/astro.svg`.
Hint:
  If you want to use an image from your `src` folder, you need to either import it or if the image is coming from a content collection, use the image() schema helper https://docs.astro.build/en/guides/images/#images-in-content-collections. See https://docs.astro.build/en/reference/modules/astro-assets/#src-required for more information on the `src` property.
Error reference:
  https://docs.astro.build/en/reference/errors/local-image-used-wrongly/

That’s a lot of words. The fix is short.

How to fix it

  1. Find the line. Look for <Image with src="..." in quotes. The error shows the path. It comes right after the word Received.
  2. Import the picture. At the top of the file, inside the --- lines, add an import. Give the picture a short name, like logo.
  3. Use the name in curly brackets. Change src="../assets/astro.svg" to src={logo}.

Here is our page after the fix:

---
import { Image } from 'astro:assets';
import logo from '../assets/astro.svg';
---
<h1>About me</h1>
<Image src={logo} alt="The Astro logo" />

We built again, and it worked. Then we looked in the built page, dist/about/index.html. Astro had made this tag. It even added the width and height:

<img src="/_astro/astro.Dm8K3lV8_28Kit4.svg" alt="The Astro logo" loading="lazy" decoding="async" width="115" height="48">

Still stuck?

Where to go next

Frequently asked questions

Why can't I just type the path to my image?

Astro has to read the picture to shrink it and find its size. It can only do that for pictures you import. A typed path is just words to Astro.

What if my image is in the public folder?

Use a plain img tag for those, like img src=/photo.jpg. If you use the Image component instead, you must add a width and a height.

Do I put .src after the imported image?

No. Pass the whole thing, like src={photo}. Astro's docs warn against src={photo.src}.

Stuck on a step?

Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astronursery.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".