question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken node support? (CanvasPattern.setTransform)

See original GitHub issue

Attach (recommended) or Link to PDF file here https://github.com/mozilla/pdf.js/blob/8ab65ed32d0f99a5fd5bf6ce302acb25082910c0/test/pdfs/issue7847_radial.pdf

Configuration:

  • Web browser and its version: NodeJS v14.17.1, node-canvas v2.8.0
  • Operating system and its version: Windows v10.0.18363
  • PDF.js version: 0afc785c7d0de39ab79f6bb60d8f60daa3f8477b
  • Is a browser extension: no

Steps to reproduce the problem:

$ npm install
$ gulp dist-install
$ npm install canvas
$ cd examples/node/pdf2png
$ node pdf2png.js ../../../test/pdfs/issue7847_radial.pdf

What is the expected behavior? (add screenshot)

As of ac44afa70e06d103633727a3249cf049c00d3fd0, pattern_helper.js makes use of CanvasPattern.setTransform(...), which has unfortunately not been implemented yet in the node canvas (https://github.com/Automattic/node-canvas/issues/1411). Previously I’ve been able to use the pattern helper from within Node contexts.

What went wrong? (add screenshot)

# PDF document loaded.
(node:1608) UnhandledPromiseRejectionWarning: TypeError: pattern.setTransform is not a function
    at RadialAxialShadingPattern.getPattern (/tmp/pdf.js/build/dist/legacy/build/pdf.js:15919:15)
    at CanvasGraphics.fill (/tmp/pdf.js/build/dist/legacy/build/pdf.js:14612:37)
    at CanvasGraphics.executeOperatorList (/tmp/pdf.js/build/dist/legacy/build/pdf.js:14116:24)
    at InternalRenderTask._callee4$ (/tmp/pdf.js/build/dist/legacy/build/pdf.js:12335:51)
    at tryCatch (/tmp/pdf.js/build/dist/legacy/build/pdf.js:832:17)
    at Generator.invoke [as _invoke] (/tmp/pdf.js/build/dist/legacy/build/pdf.js:1005:22)
    at Generator.next (/tmp/pdf.js/build/dist/legacy/build/pdf.js:875:21)
    at asyncGeneratorStep (/tmp/pdf.js/build/dist/legacy/build/pdf.js:9508:103)
    at _next (/tmp/pdf.js/build/dist/legacy/build/pdf.js:9510:194)
    at /tmp/pdf.js/build/dist/legacy/build/pdf.js:9510:364
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1608) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:1608) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kmcclellancommented, Jul 13, 2021

I can confirm that running with a local build of Automattic/node-canvas#1623 resolves this.

1reaction
Snuffleupaguscommented, Jul 15, 2021

Closing this issue, since there’s not much more we can do here now, given that:

  1. We’ll now at least catch these errors, such that the rest of the page can finish rendering, please see PR #13725.
  2. The upstream node-canvas PR, see https://github.com/Automattic/node-canvas/pull/1623, was just merged; hence this should thus be completely fixed with a future release of that package.
Read more comments on GitHub >

github_iconTop Results From Across the Web

CanvasPattern.setTransform() - Web APIs | MDN
This is just a simple code snippet which uses the setTransform method to create a CanvasPattern with the specified pattern transformation ...
Read more >
canvas | Yarn - Package Manager
Breaking. Drop support for Node.js <6.x; Remove sync stream functions (bc53059). Note that most streams are still synchronous (run in the main thread);...
Read more >
Canvas Element - HTML Standard - whatwg
Returns an object that exposes an API for drawing on the canvas. contextId specifies the desired API: " 2d ", " bitmaprenderer ",...
Read more >
HTML Canvas 2D Context - W3C
Abstract. This specification defines the 2D Context for the HTML canvas element. The 2D Context provides objects, methods, and properties to ...
Read more >
https://raw.githubusercontent.com/Automattic/node-...
CanvasPattern's `setTransform` method is no longer missing ### Fixed * Fix BMP ... new ``` ### Breaking * Drop support for Node.js <6.x...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found