Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next 14.2.12 with react-pdf and pdfjs-dist | Build fails with webpack error: TypeError: Promise.withResolvers is not a function | Passes Vercel build with swcMinify: false #70239

Open
justin-algoleaf opened this issue Sep 19, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js.

Comments

@justin-algoleaf
Copy link

justin-algoleaf commented Sep 19, 2024

Link to the code that reproduces this issue

https://github.com/algoleaf/pdf-test

To Reproduce

  1. npm run dev
  2. Browse to localhost:3000/
  3. Observe Webpack error in console
  4. npm run build
  5. Observe build error: "Build failed because of webpack errors" (log error code exceeds 4 MB, so I didn't include a screenshot here)

Current vs. Expected behavior

Context
I'm building a Next app leveraging react-pdf (9.1.1) and pdfjs-dist: (4.4.168) to load and display PDFs from a source URL (Azure Blob). The minimal reproduction provided is a single page with a component that loads in and renders a PDF.

Per the react-pdf npm doc (https://www.npmjs.com/package/react-pdf?activeTab=readme), I've included the suggested webpack config addition to my next.config.mjs file.

build_error_2

Current Behavior
The page does not compile at all when the PDF.js worker is defined in the page (server) component. The page compiles and the PDF renders properly from the source URL when PDF.js worker is placed in client component, but logs the following webpack error:

pdf_dev_error_1

When I run a local build with swcMinify disabled, I get the following error:
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Promise.withResolvers is not a function

When I run my main project with swcMinify disabled, my code passes local build and Vercel build validation.

build_error_3

When I run a local build with swcMinify truthy, I get a large webpack error (larger than 4 MB)

build_error_4

When I run my main project with swcMinify truthy, my code fails local and Vercel build validation:

build_error_1

Expected Behavior
The PDF renders and displays correctly in local development, so I would expect a successful build without a webpack error and without disabling swcMinify.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 16075
  Available CPU cores: 8
Binaries:
  Node: 20.17.0
  npm: 10.8.3
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.12 // Latest available version is detected (14.2.12).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: N/A
Next.js Config:
  output: N/A

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

SWC, Webpack

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

next dev (local), next build (local), Vercel (Deployed)

Additional context

I tried to run this minimal reproduction with canary but couldn't resolve dependencies for react-pdf 9.1.1. I also tried adding a polyfill for Promise.withResolvers but this did not work either.

My main project actually passes build validation when preview deployed to Vercel, but only when swcMinify is set to false in my next.config.mjs file. The build logs inform me that I will be unable to disable swcMinify in future versions of Next. I want to ensure my build won't break when updating Next. My main project faces the same webpack issue in local development, however.

I also noticed there was another issue submitted 2 years ago (#40803) concerning react-pdf/renderer failing to work with swcMinify set truthy. I figured I would provide the link for reference. Thank you!

@justin-algoleaf justin-algoleaf added the bug Issue was opened via the bug report template. label Sep 19, 2024
@github-actions github-actions bot added SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js. labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. SWC Related to minification/transpilation in Next.js. Webpack Related to Webpack with Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant