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

pdfjs-dist fails to compile with Turbopack (webpackIgnore comment not respected) #65406

Closed
timneutkens opened this issue May 6, 2024 · 8 comments
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.

Comments

@timneutkens
Copy link
Member

timneutkens commented May 6, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/pdf-viewer-forked-h3gdsc?file=%2Fcomponents%2FTestPage.tsx

To Reproduce

  1. Open https://codesandbox.io/p/devbox/pdf-viewer-forked-h3gdsc?file=%2Fcomponents%2FTestPage.tsx
  2. Observe the compilation failing with Module not found (example: https://h3gdsc-3000.csb.app/)

Current vs. Expected behavior

pdfjs-dist ships with a webpack specific ignore comment (:til: that is a feature) as they use import() to load a file based on an option being passed in.

Specifically const worker = await import(/* webpackIgnore: true */ this.workerSrc); fails to compile as it can't find this.workerSrc statically.

I'm not sure what the best behavior is for this, adding support for the comment or ignoring such imports when they don't include a path.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.12.0
  npm: 10.5.0
  Yarn: 1.22.19
  pnpm: 8.15.6
Relevant Packages:
  next: 14.3.0-canary.40 // Latest available version is detected (14.3.0-canary.40).
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.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 dev (local), next build (local), next start (local), Vercel (Deployed), Other (Deployed)

Additional context

This is failing on all versions with Turbopack as it doesn't support the ignore comment.

PACK-3046

@timneutkens timneutkens added the bug Issue was opened via the bug report template. label May 6, 2024
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label May 6, 2024
@timneutkens
Copy link
Member Author

This issue came out of #63385 (comment)

@enricoros

This comment was marked as off-topic.

@timneutkens
Copy link
Member Author

@enricoros adding screenshots of CLI output is not helpful in general. If you want to share that you're running into the same issue you can use GitHub's emoji reactions on the initial post to add a 👍

Thanks!

@husseinraoouf
Copy link

husseinraoouf commented Jul 20, 2024

@timneutkens this is the only thing preventing me from using turbopack with next dev now, shouldn't we add a test for the webpackIgnore case in general to make sure turbo have 100% compatibility with current webpack setup in nextjs and to better to show in the areweturboyet.com

@dmkotan
Copy link

dmkotan commented Aug 19, 2024

Used bun patch for a workaround. patch-package should work too.

diff --git a/build/pdf.mjs b/build/pdf.mjs
--- a/build/pdf.mjs
+++ b/build/pdf.mjs
@@ -11936,7 +11936,8 @@ class PDFWorker {
       if (this.#mainThreadWorkerMessageHandler) {
         return this.#mainThreadWorkerMessageHandler;
       }
-      const worker = await import( /*webpackIgnore: true*/this.workerSrc);
+      // https://github.com/vercel/next.js/issues/65406
+      const worker = await import( /*webpackIgnore: true*/this.workerSrc ?? "./pdf.worker.mjs");
       return worker.WorkerMessageHandler;
     };
     return shadow(this, "_setupFakeWorkerGlobal", loader());

@gurkerl83
Copy link
Contributor

It seems Vercel has made progress in handling Workers within Turbopack. As of Next.js 15.0.0-canary.148, the previously reported error has been resolved. This error was still present in canary.146, but no longer appears in the latest canary release.

Thx!

@timneutkens
Copy link
Member Author

timneutkens commented Oct 4, 2024

Thanks for checking @gurkerl83 this issue has indeed been resolved, we added support for webpackIgnore and turbopackIgnore and it's available on next@canary, will be in Next.js 15 RC.2 soon!

Related PR: #69768

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

5 participants