我用Vue-CLI用vuejs创建了一个项目。我已经将echarts的版本从版本-4.1.0更新到了4.2.0-rc.2版本。在更新它之后,会发生以下错误:
在'echarts/lib/echarts‘中找不到“导出’默认‘(导入为'echarts')。
TypeError:无法指定对象“#”的只读属性“导出”
在更新echarts包之前,以下是我的代码
vue.config.js文件
const path = require('path');
const webpack = require('webpack');
module.exports = {
baseUrl: process.env.NODE_ENV == 'production' ? '/' : '/',
transpileDependencies: [
/\bvue-echarts\b/,
/\bresize-detector\b/
],
configureWebpack: {
plugins: [
//jquery plugin
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery'
})
]
}
}在更新echarts版本之后,我已经用以下行替换了一些代码行:
transpileDependencies: [
/\/node_modules\/vue-echarts\//,
/\/node_modules\/resize-detector\//
],在更新这些行时,我已经解决了第一个错误。但是在echarts页面中,控制台中出现了以下错误:
挂载钩子中的错误:“错误:组件series.bar不存在。请先加载它。”
这是我的条形图文件:
<template>
<ECharts :options="bar" style="width:100%; height:300px"></ECharts>
</template>
<script>
import ECharts from "vue-echarts/components/ECharts.vue";
import "echarts/lib/chart/bar";
import "echarts/lib/component/title";
import { ChartConfig } from "Constants/chart-config";
export default {
components: {
ECharts
},
data() {
return {
bar: {
tooltip: {
trigger: "axis"
},
color: [ChartConfig.color.danger],
legend: {
data: ["Series A"]
},
xAxis: {
type: "category",
boundaryGap: true,
data: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]
},
yAxis: {
type: "value",
axisLabel: {
formatter: "{value} K"
}
},
series: [
{
name: "Series A",
type: "bar",
data: [11, 11, 15, 13, 12, 13, 10]
}
]
}
};
}
};
</script>我应该如何消除这些错误。如需更多信息,请告诉我。谢谢!
发布于 2019-02-06 10:00:31
我最终得到了解决方案,这个错误发生了,因为我们不能混合commonjs & ES模块。为了解决这个问题,我更新了babel.config.js文件:
// babel.config.js
module.exports = {
presets: [
["@vue/app", {
modules: "commonjs"
}]
]
};通过添加上述代码,您的ES模块代码将被转换到公共部分,然后传递给webpack进行编译。
https://stackoverflow.com/questions/53653468
复制相似问题