nextjs - 💡(How to fix) Fix Turbopack: CommonJS require import of 'canvas' fails to resolve when using react-pdf library (Nextjs v16.0.1) [2 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#85510Fetched 2026-04-08 02:15:19
View on GitHub
Comments
2
Participants
2
Timeline
8
Reactions
0
Timeline (top)
commented ×2labeled ×2closed ×1issue_type_added ×1

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/Dominic-Preap/nextjs-canvas-turbopack-issue

To Reproduce

  1. Clone the repo
  2. Build docker image from Dockerfile
  3. The build will fail, check the logs

Current vs. Expected behavior

Turbopack in version 16.0.1 still cannot resolve canvas library.

<img width="1006" height="799" alt="Image" src="https://github.com/user-attachments/assets/9d701dc2-36a6-40f6-b70c-69db29bb8978" />

Reference from past year https://github.com/vercel/next.js/issues/64657 https://github.com/vercel/next.js/issues/64165

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

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

Turbopack

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

next build (local)

Additional context

I tested in my M4 Mac, it built successfully, but when build from Dockerfile it fail.

extent analysis

TL;DR

The issue is likely due to Turbopack's inability to resolve the canvas library in a Docker environment, and a workaround may involve adjusting the Dockerfile or Next.js configuration.

Guidance

  • Verify that the canvas library is installed and compatible with the Node.js version used in the Docker image.
  • Check the Dockerfile for any differences in environment variables or dependencies that might affect Turbopack's behavior compared to the local build.
  • Consider adding a --legacy-peer-deps flag to the npm install or yarn install command in the Dockerfile to resolve potential peer dependency issues.
  • Investigate the differences in build environments between the local machine (M4 Mac) and the Docker container to identify potential causes for the discrepancy.

Example

No code snippet is provided as the issue is more related to environment and configuration.

Notes

The issue may be specific to the Docker environment or the combination of Next.js and Turbopack versions used. Further investigation into the Dockerfile and build process is necessary to determine the root cause.

Recommendation

Apply workaround: Adjust the Dockerfile or Next.js configuration to resolve the canvas library issue, as the problem seems to be environment-specific rather than a version-related issue that could be fixed by upgrading.

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

nextjs - 💡(How to fix) Fix Turbopack: CommonJS require import of 'canvas' fails to resolve when using react-pdf library (Nextjs v16.0.1) [2 comments, 2 participants]