Skip to content
New issue

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

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

Already on GitHub? # to your account

pdfjs-dist: Jest failures with optional dependency canvas for ARM macs #16463

Closed
MattyBalaam opened this issue May 23, 2023 · 6 comments
Closed

Comments

@MattyBalaam
Copy link

MattyBalaam commented May 23, 2023

Configuration:

  • ARM MacBook
  • Ventura
  • pdfjs-dist v3.6.172

Steps to reproduce the problem:

  1. Install pdfs-dist, notice a build failure on canvas dependency (there are no prebuilt binaries), but notice the install continues
  2. Run any pre-existing browser jest tests which use jest-environment-jsdom. (no need to include pdfjs-dist anywhere)
  3. See Jest errors relating to a missing Build folder in canvas.
Screenshot 2023-05-23 at 17 44 59

This really feels like probably a jsdom and canvas issue, but in the absence of the canvas maintainer providing ARM binaries, is there a possible workaround anyone can suggest to stop this chain?

I have wondered if there is any way of uninstalling canvas programatically after install for example? Or perhaps there should be a browser-only fork of pdfjs-dist. The other option is quite drastic and would involve copying over the compiled build files.

@Snuffleupagus
Copy link
Collaborator

The canvas-package is listed in the optionalDependencies in the package.json file in the pdfjs-dist library, which should mean that it'll be skipped if unavailable. Unfortunately I don't think that we can do anything (more) about this issue here.

@Snuffleupagus Snuffleupagus closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2023
@MattyBalaam
Copy link
Author

@Snuffleupagus I understand you have attempted to use the optionalDependencies object, unfortunately the package is still installed into node_modules, but the build folder is empty.

I'll poke the jsdom maintainers instead, perhaps they can make a more robust check.

@MattyBalaam
Copy link
Author

MattyBalaam commented Jun 1, 2023

In case anyone else comes across the same issue, I have a horrible little workaround which works in my case. Note that this will mean that if you need to use a canvas in a node environment this will not help you.

We are using yarn so we were able to add a new entry to the resolutions object in package.json: "canvas": "./__BLOCKED_MODULE" where __BLOCKED_MODULE is a local folder just with a basic package.json file. This means that node-canvas does not get pulled and therefore jsdom does not fail when trying to import/require expected files.

@blackbing
Copy link

@MattyBalaam's solution is horrible but work.

@MattyBalaam
Copy link
Author

@MattyBalaam's solution is horrible but work.

Yep, it certainly is!

@msileo
Copy link

msileo commented Apr 18, 2024

Came across this as well after installing pdfjs-dist
The solution works but for now just keeping it stashed for when running jest unit tests instead of committing as it is kind of gross :/

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants