Closed jribbens closed 6 months ago
The 2.1.1 version was a sad mistake, it shouldn't have been released.
It was supposed to be a major 3 version. Going forward this kind of import you're showing here should instead be made from the path2d
library
something like this:
path2d = await __non_webpack_import__("path2d");
(function checkPath2D() {
if (globalThis.Path2D || !isNodeJS) {
return;
}
const CanvasRenderingContext2D = canvas?.CanvasRenderingContext2D;
const applyPath2DToCanvasRenderingContext = path2d?. applyPath2DToCanvasRenderingContext;
if (CanvasRenderingContext2D && applyPath2DToCanvasRenderingContext) {
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
applyPath2DToCanvasRenderingContext(CanvasRenderingContext2D);
} else {
warn("Cannot polyfill `Path2D`, rendering may be broken.");
}
})();
}
Something about the way you've split the packages breaks pdf.js and makes it emit a warning:
Warning: Cannot polyfill 'Path2D', rendering may be broken.
pdf.js imports path2d-polyfill by doing:
This works fine in
path2d-polyfill
2.0.1 but in 2.1.1 this throws the exceptionError [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .../node_modules/path2d-polyfill/package.json
. So I guess whatever an "exports main" is, you need to define one and then publish a version 2.1.2 to un-break pdf.js.