Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
16.2 Jest tests fail when using a custom image loader | GoodFirstPicks

16.2 Jest tests fail when using a custom image loader

vercel/next.js 0 comments 6d ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeTest focusedNext.jsTypeScriptReact

Why this is a good first issue

Jest tests fail when using a custom image loader in Next.js 16.2.

AI Summary

The issue involves Jest tests failing when using a custom image loader in Next.js 16.2, despite the loader being correctly configured in `next.config.js`. The problem appears to be specific to the testing environment and requires understanding both Jest and Next.js's image handling mechanisms. The issue started in version 16.2 and was not present in 16.1.

Issue Description

Link to the code that reproduces this issue

https://github.com/guisehn/next-16.2-jest-bug-mre

To Reproduce

  1. Configure your next.config.js with a custom loader by using loader and loaderFile (docs)

  2. Use npm run test to run a Jest test that renders a next/image

  3. It will crash with:

Image with src "/images/test.jpg" is missing "loader" prop.
Read more: https://nextjs.org/docs/messages/next-image-missing-loader

Current vs. Expected behavior

Currently: crashing with error Image with src "/images/test.jpg" is missing "loader" prop.

Expected: not crash, because loaderFile was supplied in next.config.js.

This error should only happen when using loader = custom but not having a loaderFile. In that case, passing a loader prop to next/image is required.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 22.1.0
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: 10.16.1
Relevant Packages:
  next: 16.2.1 // Latest available version is detected (16.2.1).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Testing

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Issue started happening on Next.js 16.2. Tested and it works fine on 16.1.

GitHub Labels

Testing

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!

Risk Flags

  • requires understanding of Jest and Next.js image handling
Loading labels...

Details

Points20 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedyes