I want to code a desktop application using Electron, nuxt.js and am4charts. When importing the am4charts core with
import * as am4core from '@amcharts/amcharts4/core'
the app returns an error:
JavaScript
x
5
1
export { System, system } from "./.internal/core/System";
2
^^^^^^
3
4
SyntaxError: Unexpected token export
5
My setup:
- Electron-nuxt boilerplate (https://github.com/michalzaq12/electron-nuxt)
- “@amcharts/amcharts4”: “^4.7.1”
I already tried to transpile amCharts in nuxt.config.js using
JavaScript
1
7
1
build: {
2
transpile: [
3
'@amcharts/amcharts4'
4
],
5
vendor: ['v-tooltip']
6
}
7
but without success. How can I fix this issue?
Advertisement
Answer
I found it could be known issue between nuxt.js and amcharts.js and it has a solution as follows:
create a file plugins/amcharts.js
JavaScript
1
16
16
1
import * as am4core from "@amcharts/amcharts4/core";
2
import * as am4charts from "@amcharts/amcharts4/charts";
3
import am4themes_animated from "@amcharts/amcharts4/themes/animated";
4
import am4themes_dark from "@amcharts/amcharts4/themes/dark";
5
6
import Vue from "vue";
7
8
Vue.prototype.$am4core = () => {
9
return {
10
am4core,
11
am4charts,
12
am4themes_animated,
13
am4themes_dark
14
}
15
}
16
then add to nuxt.config.js
JavaScript
1
7
1
plugins: [
2
{
3
src: '~/plugins/amCharts.js',
4
ssr: false
5
}
6
],
7
in components file
JavaScript
1
4
1
mounted() {
2
let {am4core, am4charts, am4themes_animated, am4themes_dark} = this.$am4core();
3
}
4
Solution is found on Github: https://github.com/nuxt/nuxt.js/issues/3336