nilzona / path2d-polyfill

Polyfills Path2D api for canvas rendering
29 stars 10 forks source link

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

Open gianlazz opened 3 weeks ago

gianlazz commented 3 weeks ago

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",
  ...
  }
...
}
nilzona commented 3 weeks ago

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?