nextjs - ✅(Solved) Fix `Object.defineProperty called on non-object` error with pdfjs-dist in webpack mode (possibly related to webpack/webpack#20095) [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#89177Fetched 2026-04-08 02:03:13
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
4
Author
Participants
Timeline (top)
cross-referenced ×2subscribed ×2commented ×1issue_type_added ×1

Error Message

  1. See error in console: Uncaught TypeError: Object.defineProperty called on non-object

Fix Action

Fixed

PR fix notes

PR #89569: Update the webpack version bundled in next

Description (problem / solution / changelog)

Upgrade webpack 5.98.0 → 5.105.0

Updates webpack from 5.98.0 to 5.105.0 and webpack-dev-server from 5.2.0 to 5.2.3.

Notable webpack changes

New Features:

  • Native tsconfig resolver option - can replace tsconfig-paths-webpack-plugin (v5.105.0)
  • import.defer() support for context modules (v5.105.0)
  • Array values for devtool option (v5.105.0)
  • Built-in DotenvPlugin and top-level dotenv option (v5.103.0)
  • Built-in WebpackManifestPlugin (v5.103.0)
  • import.meta.env, import.meta.dirname, import.meta.filename support (v5.103.0)
  • CSS exportType option (link, text, css-style-sheet) (v5.103.0)
  • New import types: { type: "bytes" } and { type: "text" } (v5.102.0)
  • Tree-shaking for ESM external modules with named imports (v5.101.0)

Stabilized (no longer experimental):

Bug Fixes & Security:

  • Security fix in HttpUriPlugin (v5.104.1)
  • Various fixes for reexport runtime calculations, module concatenation performance

webpack-dev-server 5.2.0 → 5.2.3

  • ESC key to dismiss error overlay (v5.2.3)
  • Fixed crash when error is null for runtime errors (v5.2.2)
  • Improved cross-origin request validation (v5.2.1)

HMR race condition fix

Webpack 5.104+ added a module existence check in `webpack_require` (when `output.pathinfo` is true, the default in dev mode) that surfaced a pre-existing race condition in Next.js's HMR protocol.

The race: When a server component changes, the dev server sends `BUILT` (triggering async `module.hot.apply()`) followed by `SERVER_COMPONENT_CHANGES` (triggering `hmrRefresh()`). Previously, `hmrRefresh()` fired immediately without waiting for the webpack update to finish, so `webpack_require` could be called for client components that were temporarily absent from `webpack_modules` during the swap. This was silently caught by React error boundaries with old webpack, but the new explicit module existence check turns it into a hard error.

The fix: Wait for the pending webpack HMR promise to resolve before calling `hmrRefresh()`, ensuring all modules are fully in place before the RSC response references them.

Known Breaking changes

Breaking change for `experimental.urlImports` users: Webpack 5.105.0 now validates redirect target URLs against the `allowedUris` policy. If your URL imports redirect to a different domain (e.g., `github.com/...` → `raw.githubusercontent.com/...`), you must add the redirect target domain to your `urlImports` array.

Full changelogs

Blocked on https://github.com/webpack/webpack/issues/20475

Fixes #89177

Changed files

  • docs/01-app/03-api-reference/05-config/01-next-config-js/urlImports.mdx (modified, +15/-0)
  • package.json (modified, +4/-3)
  • packages/next/package.json (modified, +1/-1)
  • packages/next/src/build/utils.ts (modified, +1/-1)
  • packages/next/src/build/webpack-config.ts (modified, +3/-2)
  • packages/next/src/build/webpack/loaders/next-flight-loader/index.ts (modified, +4/-0)
  • packages/next/src/build/webpack/plugins/css-minimizer-plugin.ts (modified, +6/-1)
  • packages/next/src/build/webpack/plugins/eval-source-map-dev-tool-plugin.ts (modified, +5/-6)
  • packages/next/src/build/webpack/plugins/minify-webpack-plugin/src/index.ts (modified, +12/-11)
  • packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts (modified, +4/-2)
  • packages/next/src/bundles/webpack/packages/HotModuleReplacement.runtime.js (modified, +41/-29)
  • packages/next/src/bundles/webpack/packages/JavascriptHotModuleReplacement.runtime.js (modified, +43/-33)
  • packages/next/src/bundles/webpack/packages/lazy-compilation-node.js (modified, +45/-29)
  • packages/next/src/bundles/webpack/packages/lazy-compilation-universal.js (added, +18/-0)
  • packages/next/src/bundles/webpack/packages/lazy-compilation-web.js (modified, +15/-5)
  • packages/next/src/bundles/webpack/packages/load-http.js (added, +7/-0)
  • packages/next/src/client/dev/hot-reloader/app/hot-reloader-app.tsx (modified, +17/-9)
  • packages/next/src/compiled/mini-css-extract-plugin/cjs.js (modified, +1/-1)
  • packages/next/src/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js (modified, +1/-1)
  • packages/next/src/compiled/mini-css-extract-plugin/index.js (modified, +1/-1)
  • packages/next/src/compiled/mini-css-extract-plugin/loader.js (modified, +1/-1)
  • packages/next/src/compiled/sass-loader/cjs.js (modified, +1/-1)
  • packages/next/src/compiled/webpack/HotModuleReplacement.runtime.js (modified, +41/-29)
  • packages/next/src/compiled/webpack/JavascriptHotModuleReplacement.runtime.js (modified, +43/-33)
  • packages/next/src/compiled/webpack/bundle5.js (modified, +4/-4)
  • packages/next/src/compiled/webpack/emitter-event-target.js (added, +1/-0)
  • packages/next/src/compiled/webpack/lazy-compilation-node.js (modified, +45/-29)
  • packages/next/src/compiled/webpack/lazy-compilation-universal.js (added, +18/-0)
  • packages/next/src/compiled/webpack/lazy-compilation-web.js (modified, +15/-5)
  • packages/next/src/compiled/webpack/load-http.js (added, +7/-0)
  • packages/next/src/server/dev/hot-reloader-webpack.ts (modified, +4/-3)
  • packages/next/taskfile.js (modified, +30/-1)
  • pnpm-lock.yaml (modified, +468/-242)
  • test/development/middleware-errors/index.test.ts (modified, +1/-1)
  • test/e2e/url-imports/next.config.js (modified, +1/-0)

Code Example

Operating System:
    Platform: darwin
    Arch: arm64
    Version: Darwin 25.2.0
  Binaries:
    Node: 22.x
    pnpm: 10.x
  Relevant Packages:
    next: 16.1.6
    react: 19.0.0
    react-pdf: 10.3.0
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/makotot/next-react-pdf-webpack-issue

To Reproduce

  1. Clone the reproduction repository
  2. pnpm install
  3. pnpm dev (runs next dev --webpack)
  4. Open http://localhost:3000 in browser
  5. See error in console: Uncaught TypeError: Object.defineProperty called on non-object

Current vs. Expected behavior

Current: When using react-pdf (which depends on pdfjs-dist) with Next.js 16 and webpack mode, the app crashes with TypeError: Object.defineProperty called on non-object.

Expected: The app should work without errors.

Provide environment information

Operating System:
    Platform: darwin
    Arch: arm64
    Version: Darwin 25.2.0
  Binaries:
    Node: 22.x
    pnpm: 10.x
  Relevant Packages:
    next: 16.1.6
    react: 19.0.0
    react-pdf: 10.3.0

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

Webpack

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

next dev (local)

Additional context

This issue appears to be the same as webpack/webpack#20095, which was fixed in webpack 5.103.0. Next.js 16.1.6 lists webpack 5.98.0 in devDependencies, which is likely bundled in dist/compiled/webpack/bundle5.js.

May be related: #52542

extent analysis

TL;DR

Upgrade to a version of Next.js that bundles webpack 5.103.0 or later to fix the Object.defineProperty called on non-object error.

Guidance

  • The issue is likely caused by a known bug in webpack, which was fixed in version 5.103.0.
  • To verify the issue, check the version of webpack bundled with Next.js by inspecting the devDependencies in the package.json file or the dist/compiled/webpack/bundle5.js file.
  • As a temporary workaround, consider using a custom webpack configuration that overrides the bundled version with webpack 5.103.0 or later.
  • Check the Next.js release notes to see if a version newer than 16.1.6 is available that bundles the fixed version of webpack.

Example

No code snippet is provided as the issue is related to a specific version of webpack and Next.js.

Notes

The provided information suggests that the issue is related to a known bug in webpack, and upgrading to a version of Next.js that bundles the fixed version of webpack should resolve the issue. However, without direct access to the codebase, it's difficult to provide a more specific solution.

Recommendation

Apply workaround: Upgrade to a version of Next.js that bundles webpack 5.103.0 or later, as this is likely to fix the underlying issue with Object.defineProperty called on non-object.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING