question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server Error when using annotation plugin with Chart.js 4.0.1 in NextJS app

See original GitHub issue

Hey guys,

First of all, thanks for making this super helpful library!

I am currently working on a NextJS and have implemented ChartJS v4.0.1. All works well, but when I want to install the annotation plugin and follow the steps of https://www.chartjs.org/chartjs-plugin-annotation/latest/guide/integration.html I get the following error: Schermafbeelding 2022-12-01 om 11 25 58

My React component is: (only relevant is shown)

import {useEffect, useState} from "react";
import {BarElement, CategoryScale, Chart as ChartJS, Legend, LinearScale, Title, Tooltip} from 'chart.js';
import Annotation from 'chartjs-plugin-annotation';
import {Bar} from 'react-chartjs-2';

ChartJS.register(
    CategoryScale,
    LinearScale,
    BarElement,
    Title,
    Tooltip,
    Legend,
    Annotation,
);

.........

Do you guys have any idea how to solve this? Is it an issue because of ChartJS v4?

Thanks a lot!

Cheers, Ferre

Issue Analytics

  • State:open
  • Created 10 months ago
  • Reactions:4
  • Comments:12

github_iconTop GitHub Comments

2reactions
fdevcommented, Dec 15, 2022

I’ve been using the changes from the PR of @stockiNail with success using the following patch file for patch-package:

diff --git a/node_modules/chartjs-plugin-annotation/package.json b/node_modules/chartjs-plugin-annotation/package.json
index f7b8c12..45e3d9d 100644
--- a/node_modules/chartjs-plugin-annotation/package.json
+++ b/node_modules/chartjs-plugin-annotation/package.json
@@ -5,8 +5,15 @@
   "version": "2.1.0",
   "author": "Evert Timberg <evert.timberg@gmail.com>",
   "license": "MIT",
-  "main": "dist/chartjs-plugin-annotation.js",
-  "module": "dist/chartjs-plugin-annotation.esm.js",
+  "type": "module",
+  "main": "dist/chartjs-plugin-annotation.esm.js",
+  "jsdelivr": "dist/chartjs-plugin-annotation.min.js",
+  "unpkg": "dist/chartjs-plugin-annotation.min.js",
+  "exports": {
+    "types": "./types/index.d.ts",
+    "import": "./dist/chartjs-plugin-annotation.esm.js",
+    "require": "./dist/chartjs-plugin-annotation.min.js"
+  },
   "types": "types/index.d.ts",
   "repository": {
     "type": "git",

Don’t forget to remove the .next folder before running npm run dev, or it will use a cached unpatched version of chartjs-plugin-annotation.

1reaction
TraceLosucommented, Dec 21, 2022

Tested it with ChartJS@4.1.1 and annotation@2.1.0, works perfectly fine with box and line annotations!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · chartjs/chartjs-plugin-annotation - GitHub
Contribute to chartjs/chartjs-plugin-annotation development by creating ... Server Error when using annotation plugin with Chart.js 4.0.1 in NextJS app bug.
Read more >
Next.js build error No "exports" main defined with chart.js
I am currently moving from craco (react-scripts) to Next.js but I have a problem in the build step. If I run the app...
Read more >
chartjs-plugin-annotation-fix - npm
Annotations for Chart.js. Latest version: 0.5.8, last published: 4 years ago. Start using chartjs-plugin-annotation-fix in your project by ...
Read more >
Integration | Chart.js
The examples below show how to load Chart.js in different systems. If you're using a front-end framework (e.g., React, Angular, or Vue), please ......
Read more >
nx jest unexpected token 'export' - You.com | The AI Search ...
I use Jest to create and run the unit test used in my monorepo. Problem. When I run jest, on some test it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found