[Chartjs]-Error: Cannot find module 'canvas' โ€“ Chart.js

2๐Ÿ‘

โœ…

On https://www.npmjs.com/package/chartjs-node-canvas, thereโ€™s the following note:

Node JS version

This is limited by the upstream dependency canvas.

Therefore, your problem should be solved if you run the following commands:

npm install canvas
npm rebuild

1๐Ÿ‘

open New terminal and write npm command to install module which is chartjs-node-canvas

npm install canvas 
npm install chartjs-node-canvas

0๐Ÿ‘

I made a blank canvas module, it seems to work.

  1. Edit package.json:
  "dependencies": {
    "canvas": "file:./src/lib/canvas",
    "jsdom": "^21.1.1",
  1. Create a directory canvas in that path and index.ts/js with:
module.exports = {};
  1. npm i
  2. Run the app.

The solution originates from here.

Leave a comment