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.
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)

3 participants