apertureless / vue-chartjs

📊 Vue.js wrapper for Chart.js
https://vue-chartjs.org
MIT License
5.55k stars 836 forks source link

[Bug]: Still problem with Vue 2.7 #975

Closed frufin closed 1 year ago

frufin commented 1 year ago

Would you like to work on a fix?

Current and expected behavior

HI, I'm using vue-cli & Vue 2.7.10 Both vue-chartjs & chart.js successefully installed using Yarn

I get an error trying to import vue-chartjs from a component:

import { Bar } from 'vue-chartjs'

=>

Failed to compile.

./src/components/main/views/server/Status.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/main/views/server/Status.vue?vue&type=script&lang=js&)
Module not found: Error: Can't resolve 'vue-chartjs' in '/Users/fredericrufin/Sites/webapachekit/src/components/main/views/server'

Reproduction

Failed to compile. ./src/components/main/views/server/Status.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/main/views/server/Status.vue?vue&type=script&lang=js&) Module not found: Error: Can't resolve 'vue-chartjs' in '/Users/fredericrufin/Sites/webapachekit/src/components/main/views/server'

chart.js version

4.0.1

vue-chartjs version

5.0.1

Possible solution

No response

dotob commented 1 year ago

same here

apertureless commented 1 year ago

Hi @frufin, as vue-chartjs 5 is esm only, have you set your project type to module in package.json ? https://vue-chartjs.org/migration-guides/#esm

dangreen commented 1 year ago

@frufin @dotob Hi. I can offer 3 options here:

1) Migrate to ESM, as @apertureless said 2) Configure webpack 3) Soon, Chart.js will be released with restored CommonJS support. We will restore CommonJS support too, so you can wait for the release with it.

frufin commented 1 year ago

Hi @apertureless & @dangreen I suspected this problem...

Unless you have a solution to propose, I think I'll have to downgrade chart.js and vue-chartj while waiting for commonJS support...

I suppose i'll have to downgrade vue-chartj to v4.12 and downgrade charts.js to v3.9 Or does a CDN exist for vue-chartjs v5 ?

Thanks

frufin commented 1 year ago

Seems to work using version 5 from CDN

dangreen commented 1 year ago

@frufin Hi. Chart.js v4.1 and vue-chartjs v5.1 were released with restored CommonJS support.

https://vue-chartjs.org/migration-guides/#esm

nthungdev commented 1 year ago

@frufin Hi. Chart.js v4.1 and vue-chartjs v5.1 were released with restored CommonJS support.

https://vue-chartjs.org/migration-guides/#esm

Works for me now. Thank you very much!