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

Next.Js 16.1.6 Webpack Mode Crashes With Pdfjs-Dist Due To Bundled Webpack <5.103.0 Bug (Object.DefineProperty On Non-Object)

When using react-pdf (which depends on pdfjs-dist) with Next.js 16.1.6 in webpack mode, the browser throws 'Uncaught TypeError: Object.defineProperty called on non-object'. This is caused by a known webpack bug (webpack/webpack#20095) fixed in webpack 5.103.0. Next.js 16.1.6 bundles webpack 5.98.0, so the bug is not yet fixed in Next.js. A temporary workaround is to alias pdfjs-dist to its CommonJS legacy build in next.config.js.

highConfidence 78%Next.jsPages RouterApp RouterAffected V16.1.6

Origin Analysis

Next.js 16.1.6 uses a bundled webpack version 5.98.0, which contains the bug webpack/webpack#20095. This bug causes webpack to call Object.defineProperty on a non-object when handling certain ESM modules (such as pdfjs-dist's modern build), leading to the runtime error. The underlying design flaw is that Next.js tightly couples its internal webpack version, preventing users from upgrading webpack independently.
1. Clone https://github.com/makotot/next-react-pdf-webpack-issue 2. Run 'pnpm install' 3. Run 'pnpm dev' (executes 'next dev --webpack') 4. Open http://localhost:3000 in browser 5. Observe console error: 'Uncaught TypeError: Object.defineProperty called on non-object'

Fixing Code Block

Edge Case Audit

This is a workaround, not an official fix. Using the legacy build may increase bundle size and may not include the latest pdf.js features or optimizations. When Next.js releases a version with bundled webpack >=5.103.0, remove this alias and test thoroughly to avoid potential regressions. Additionally, the alias path must be updated if pdfjs-dist changes its legacy build location in future versions. If both client and server rendering occur, ensure the alias is applied in all relevant webpack configurations (Next.js applies this config to both client and server bundles automatically). Rollback: simply remove the webpack alias block and restore the default resolution.

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