Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

PDF.js + Webpack encounters Error: Value is none of these types 'String', 'Path' when Path instances pass through bundled code. Webpack's transformation causes napi-rs to classify Path instances as Unknown rather than &Path, triggering immediate failure.

Changes

src/path.rs

  • Added Env parameter to constructor (napi-rs injected, no JS API change)
  • Implemented FromNapiValue::from_napi_value fallback to extract Path from Unknown values
  • Fixed error message typo

test/path-constructor.spec.ts

  • Added tests verifying constructor accepts Path instances, strings, and creates independent copies

Example

// This now works correctly with webpack-bundled code
const original = new Path2D();
original.rect(0, 0, 100, 100);

const copy = new Path2D(original); // Previously failed with webpack

The fix handles the Unknown case by attempting to unwrap the Path instance before failing, maintaining full backward compatibility.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>PDF.js + Webpack runs into type error: Value is non of these types String, Path</issue_title>
<issue_description>An earlier issue, #994, has been resolved as of 0.1.72. A similar issue, since that release, for all combinations of PDF.js and @napi-rs/canvas, has appeared with a similar type error:

Error: Value is non of these types `String`, `Path`, 
    at CanvasGraphics.consumePath (/Users/cybourgeoisie/Documents/Cybourgeoisie/webpack-pdfjs-napirscanvas-test/dist/626.main.js:16611:15)
    at CanvasGraphics.endPath (/Users/cybourgeoisie/Documents/Cybourgeoisie/webpack-pdfjs-napirscanvas-test/dist/626.main.js:15634:10)
    at CanvasGraphics.constructPath (/Users/cybourgeoisie/Documents/Cybourgeoisie/webpack-pdfjs-napirscanvas-test/dist/626.main.js:15543:13)
    at CanvasGraphics.executeOperatorList (/Users/cybourgeoisie/Documents/Cybourgeoisie/webpack-pdfjs-napirscanvas-test/dist/626.main.js:15104:23)
    at InternalRenderTask._next (/Users/cybourgeoisie/Documents/Cybourgeoisie/webpack-pdfjs-napirscanvas-test/dist/626.main.js:20642:37)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'InvalidArg'
}

Similar to the previous issue, this issue does not show up when running in dev, but it does show up in the built code with webpack.

I have updated the test repo with the current versions for reproduction: https://github.com/Cybourgeoisie/webpack-pdfjs-napirscanvas-test</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Oct 31, 2025
Copilot AI changed the title [WIP] Fix type error in PDF.js and Webpack integration Fix Path2D constructor handling of webpack-bundled instances Oct 31, 2025
Copilot AI requested a review from Brooooooklyn October 31, 2025 13:51
Copilot finished work on behalf of Brooooooklyn October 31, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDF.js + Webpack runs into type error: Value is non of these types String, Path

2 participants