path2d-polyfill icon indicating copy to clipboard operation
path2d-polyfill copied to clipboard

Cannot assign to readonly property 'clip' of object '#<CanvasRenderingContext2D'

Open gianlazz opened this issue 1 year ago • 2 comments

Hello, I'm trying to use this library, for NextJS server-side rendering for a ChartJS plugin that requires Path2D to work. However, when I build the project I get the following error when adding the polyfill.

node_modules\path2d\dist\index.js (468:41) @ applyPath2DToCanvasRenderingContext
TypeError: Cannot assign to readonly property 'clip' of object '#<CanvasRenderingContext2D>'

Dependency Versions:

{
...
"dependencies": { 
  "canvas": "^3.0.0-rc2",
  "chart.js": "^4.4.3",
  "chartjs-plugin-annotations": "^3.0.1",
  "next": "13.5.6",
  "path2d": "^0.2.1",
  ...
  }
...
}

gianlazz avatar Oct 07 '24 22:10 gianlazz

Looks like your version of CanvasRenderingContext2D has readonly properties. If that's the case, the polyfill will work bad.

Can you post a reproducing example perhaps?

nilzona avatar Oct 08 '24 12:10 nilzona

I started getting the same error that loads this package in a node environment. There was no error when running node 18, but the error showed up when upgrading to node 20. Did node 20 make these properties read-only?

callen1994 avatar Nov 19 '24 20:11 callen1994

I believe this is not an issue anymore, please let me know if that's not the case.

nilzona avatar Jun 24 '25 14:06 nilzona