Skip to content

Conversation

@jagadish-555
Copy link

Description

This PR fixes a compatibility issue with Next.js 16 where importing pdfjs-dist causes an Object.defineProperty error.

The issue arises because the combination of outputModule: true and output.globalObject: "globalThis" in the Webpack configuration generates code that is incompatible with the Webpack runtime used by Next.js (specifically when using eval-based source maps).

Changes

  • Removed output.globalObject = "globalThis" from gulpfile.mjs

This setting is unnecessary for ES Module builds (library.type: "module") and removing it resolves the conflict, allowing pdfjs-dist to be imported correctly in Next.js environments.

Fixes #20478

@calixteman
Copy link
Contributor

This setting is unnecessary for ES Module builds ...

Could you give some pointers about that ?

@jagadish-555
Copy link
Author

This setting is unnecessary for ES Module builds ...

Could you give some pointers about that ?

ESM builds do not use the global object at all. They rely purely on import/export.
output.globalObject only applies to non-ESM formats (UMD/IIFE).
Leaving it in forces Webpack to inject unnecessary global-handling code, which conflicts with Next.js 16's runtime.
Removing it produces a correct ESM output.

Removed unnecessary blank lines in the configuration.
@ballin98
Copy link

I'm experiencing the same issue. Any updates on this PR?

@nicolo-ribaudo
Copy link
Contributor

nicolo-ribaudo commented Dec 16, 2025

This setting still affects the global property, even in an ESM build, so removing it it's a breaking change. It should be eventually done though.

On a side note, Next.js should be fixed to not crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TypeError: Object.defineProperty called on non-object when importing pdfjs-dist 5.4.449 in Next.js 16 (webpack)

5 participants