ホーム > Vue > Can't Use Chart.js? How to Fix 'Module parse failed Unexpected token'
Vue

Can't Use Chart.js? How to Fix 'Module parse failed Unexpected token'

Thank you for your continued support.
This article contains advertisements that help fund our operations.

Table Of Contents

  1. Background
  2. Solution

A guide on how to resolve the issue when Chart.js doesn't work in Vue, specifically fixing the 'Module parse failed Unexpected token' error.

Background

When I tried to use Chart.js with Vue, I ran the following command:

npm install chart.js

However, I encountered the following error:

ERROR in ./node_modules/chart.js/dist/chart.esm.js Module parse failed: Unexpected token (6813:12)

Solution

The Chart.js version was not compatible with the Vue version

In my case, I was using Vue 2, so running:

npm install chart.js@2.9.4

resolved the issue!

I hope this helps someone.

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!