vue3-apexcharts icon indicating copy to clipboard operation
vue3-apexcharts copied to clipboard

Can't install vue3 apex charts on Nuxt App

Open brainlet-ali opened this issue 4 years ago • 12 comments

In newly created Nuxt app every time I try to install apex chart via:

npm install --save apexcharts npm install --save vue3-apexcharts

Here is log of errors:

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: [email protected] npm ERR! node_modules/vue npm ERR! peer vue@"> 3.0.0" from [email protected] npm ERR! node_modules/vue3-apexcharts npm ERR! vue3-apexcharts@"*" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer vue@"^2.0.0" from [email protected] npm ERR! node_modules/vuex npm ERR! vuex@"^3.6.0" from @nuxt/[email protected] npm ERR! node_modules/@nuxt/vue-app npm ERR! @nuxt/vue-app@"2.14.12" from @nuxt/[email protected] npm ERR! node_modules/@nuxt/builder npm ERR! @nuxt/builder@"2.14.12" from [email protected] npm ERR! node_modules/nuxt npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /Users/ali/.npm/eresolve-report.txt for a full report.

brainlet-ali avatar Feb 09 '21 09:02 brainlet-ali

Nuxt requires Vue2, this module is meant to be for Vue 3.

soerenmartius avatar Mar 02 '21 11:03 soerenmartius

@soerenmartius I can't get this plugin to work with Nuxt 3 either, which ships with Vue 3.

D-Marc1 avatar Feb 07 '22 21:02 D-Marc1

Any update on this?

dvdhoek avatar Mar 03 '22 10:03 dvdhoek

vue3-apexcharts works well with nuxt3 in my case.

zhouzilong2020 avatar Jun 29 '22 10:06 zhouzilong2020

@zhouzilong2020 - can you share how you implemented it?

Bergrebell avatar Jul 11 '22 14:07 Bergrebell

this did the trick for me:

add apexchart as nuxt-plugin (filename with .client.js-ending is important)

# ~/plugins/apexcharts.client.js

import VueApexCharts from "vue3-apexcharts";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueApexCharts);
});

then you can just add the chart like that:

<script setup>
const chartOptions = {
  chart: {
    id: "vuechart-example",
  },
  xaxis: {
    categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998],
  },
};
const series = [
  {
    name: "series-1",
    data: [30, 40, 35, 50, 49, 60, 70, 91],
  },
];
</script>

<template>
  <apexchart
    width="500"
    type="bar"
    :options="chartOptions"
    :series="series"
  ></apexchart>
</template>

source: https://github.com/nuxt/framework/discussions/5352

Bergrebell avatar Jul 11 '22 15:07 Bergrebell

@zhouzilong2020 - can you share how you implemented it?

I did exact the same thing as you did. lol BTW, Glad to hear that you figure it out, it took me a while to find the solution.

zhouzilong2020 avatar Jul 11 '22 15:07 zhouzilong2020

Sooo frustrating... have replicated your code exactly @Bergrebell to test this... and I get;

image

So many different suggestions and solutions around but I think it comes down to 2/3 things;

  • Most of the solutions worked before Nuxt 3 went stable
  • Most of the solutions work in JS but maybe not TS somehow
  • Apexcharts has a bug now that needs resolving

image

Could have been amazing but not quite there yet :(

JeremyQtweb avatar Dec 08 '22 23:12 JeremyQtweb

Annnd I just fixed it by trying the <ClientOnly> wrapper again for the umpteenth time and BOOM... it worked HAHAHA

image

Thanks for the breadcrumb I needed @Bergrebell 👍

JeremyQtweb avatar Dec 08 '22 23:12 JeremyQtweb

@JeremyQtweb Hello, I have problumn same thing as you. can you share how you implemented it? :)

leeyesang avatar Feb 01 '23 02:02 leeyesang

it should be closed issue

karis avatar May 26 '23 23:05 karis

this did the trick for me:

add apexchart as nuxt-plugin (filename with .client.js-ending is important)

# ~/plugins/apexcharts.client.js

import VueApexCharts from "vue3-apexcharts";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueApexCharts);
});

then you can just add the chart like that:

<script setup>
const chartOptions = {
  chart: {
    id: "vuechart-example",
  },
  xaxis: {
    categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998],
  },
};
const series = [
  {
    name: "series-1",
    data: [30, 40, 35, 50, 49, 60, 70, 91],
  },
];
</script>

<template>
  <apexchart
    width="500"
    type="bar"
    :options="chartOptions"
    :series="series"
  ></apexchart>
</template>

source: nuxt/framework/discussions/5352

Updated source: https://github.com/nuxt/nuxt/discussions/16482

wobsoriano avatar Mar 18 '24 23:03 wobsoriano