AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next.Js 16.2 Jest Tests Fail With Custom Image Loader Regression

In Next.js 16.2, Jest tests rendering next/image with a custom loader configured via next.config.js (loader: 'custom' and loaderFile) crash with 'Image with src ... is missing loader prop.' This is a regression from 16.1 where the loaderFile was correctly recognized.

mediumConfidence 80%Next.jsApp RouterRoute HandlersAffected V16.2.0Affected V16.2.1

Origin Analysis

Next.js 16.2 changed the internal resolution of image loader configuration in test environments, causing the images.loaderFile from next.config.js to be ignored or not loaded when next/image is rendered during Jest tests. This makes the component treat the loader as missing and triggers the validation error.
1. Configure next.config.js with images.loader = 'custom' and images.loaderFile = './path/to/loader.js'. 2. Write a Jest test that renders a component containing next/image with a src like '/images/test.jpg'. 3. Run npm run test. The test fails with the missing loader prop error.

Fixing Code Block

// jest.setup.js import React from 'react'; jest.mock('next/image', () => ({ __esModule: true, default: ({ src, alt, width, height, ...rest }) => ( <img src={src} alt={alt} width={width} height={height} {...rest} /> ), })); // Ensure this file is loaded via jest.config.js setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
This workaround mocks next/image in Jest tests to render a plain img element, bypassing the internal loader resolution that is broken in 16.2. It restores test reliability without requiring changes to production code. Update jest.config.js to include the setup file.

Edge Case Audit

This mock hides the real next/image behavior, so tests will not catch loader-related issues or responsive layout features. Once the underlying Next.js regression is fixed, remove the mock and revert to testing the real component. Do not use this mock in production code; it only applies to test environment.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state