Skip to content

ImageMedia on template/website not uses loader #12105

Open
@tori-takashi

Description

@tori-takashi

Documentation Issue

I've just faced an issue trying with this official tutorial video
This video uses website template but I couldn't continue after seeding data.

$ pnpm run dev --port=3050
...
 ⨯ Error: Invalid src prop (http://localhost:3050/api/media/file/image-hero1.webp?2025-04-14T11:41:36.871Z) on `next/image`, hostname "localhost" is not configured under images in your `next.config.js`
See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host
    at defaultLoader (../../../src/shared/lib/image-loader.ts:70:16)
    at eval (../../../src/shared/lib/get-img-props.ts:239:13)
    at Array.map (<anonymous>)
    at generateImgAttrs (../../../src/shared/lib/get-img-props.ts:237:7)
    at getImgProps (../../../src/shared/lib/get-img-props.ts:693:24)
    at eval (../../src/client/image-component.tsx:394:64)
  68 |         const { hasRemoteMatch } = require('./match-remote-pattern')
  69 |         if (!hasRemoteMatch(config.domains, config.remotePatterns, parsedSrc)) {
> 70 |           throw new Error(
     |                ^
  71 |             `Invalid src prop (${src}) on \`next/image\`, hostname "${parsedSrc.hostname}" is not configured under images in your \`next.config.js\`\n` +
  72 |               `See more info: https://nextjs.org/docs/messages/next-image-unconfigured-host`
  73 |           ) {
  digest: '4002068781'
}
Image

It seems this documentation https://nextjs.org/docs/pages/building-your-application/optimizing/images is related to this problem, I didn't check deeply though.

To deal with it

Remove getClientSideURL()

If getClientSideURL() uses, show the error below.

src = `${getClientSideURL()}${url}?${cacheTag}`

Image

After remove it, it was fixed.

src = `${url}?${cacheTag}` // <- src props should be passed only relative path.
Image

Pass loader props to NextImage

If src string is not a relative URL, loader function should be passed.

return (
<picture className={cn(pictureClassName)}>
<NextImage
alt={alt || ''}
className={cn(imgClassName)}
fill={fill}
height={!fill ? height : undefined}
placeholder="blur"
blurDataURL={placeholderBlur}
priority={priority}
quality={100}
loading={loading}
sizes={sizes}
src={src}
width={!fill ? width : undefined}
/>
</picture>
)

  return (
    <picture className={cn(pictureClassName)}>
      <NextImage
        alt={alt || ''}
        className={cn(imgClassName)}
        fill={fill}
        height={!fill ? height : undefined}
        placeholder="blur"
        blurDataURL={placeholderBlur}
        priority={priority}
        quality={100}
        loading={loading}
        sizes={sizes}
        src={src}
        loader={imageLoader} // <- should be passed loader props like the documentation above.
        width={!fill ? width : undefined}
      />
    </picture>

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions