echarts icon indicating copy to clipboard operation
echarts copied to clipboard

Uncaught SyntaxError: Unexpected token export

Open aeolusheath opened this issue 9 years ago • 5 comments

引入echarts 导致,访问前段项目报错,如下图。 image

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 3.8.1 然后更新回3.7.2 还是同样的问题
  • Browser version [浏览器类型和版本]: chrome 61.0.3163.100
  • OS Version [操作系统类型和版本]: windows 10 和 macOS 都报同样的错误

Expected behaviour [期望结果]

ECharts option [ECharts配置项]

<script type="text/javascript">
  import echarts from 'echarts/lib/echarts'
  import 'echarts/lib/component/tooltip'
  import 'echarts/lib/chart/line'
  import 'echarts/lib/component/title'
  import 'echarts/lib/component/legend'
  export default{ 
    // vue 其他代码
   }
</script>

Other comments [其他信息]

因为我把引入highcharts 的代码给注释掉就可以正常访问了,除了这种方式,我还用了

let echarts= require('***')

的方式,会报同样的错误,我确定引入了 babel-preset-2015 也更新到了 babel-preset-env 但是还是同样的问题

aeolusheath avatar Nov 09 '17 12:11 aeolusheath

also getting this problem, our project greatly relies on echarts, please advice on how to resolve.

In any case, many thanks for the great work on this library.

ucanlendit avatar Nov 09 '17 13:11 ucanlendit

@aeolusheath @ucanlendit

The new version of echarts(v3.8.0) and its dependencies zrender(v3.7.0) change his module loading grammer from CommonJs(eg: require('xxx')) to esModule(eg: import xxx from 'xxx'). Some old module bundler like webpack(v1.0) can't correct bundle esModule, so raise error. You can try below solution:

solution 1: lock the low version echarts and zrender low version echarts and zrender use the CommonJs to loader module. Old version module bundle can auto recognize it and bundle. Edit package-lock.json(will auto generate when npm >= v5.0), Change

"echarts": {
      "version": "3.8.0",
      "resolved": "http://registry.npm.taobao.org/echarts/download/echarts-3.2.3.tgz",
      "integrity": "sha1-TwHhW/2jNS/NjvkEnxPYRIlxolg=",
      "requires": {
        "zrender": "3.7.0"
      }
    },

To

"echarts": {
      "version": "3.2.3",
      "resolved": "http://registry.npm.taobao.org/echarts/download/echarts-3.2.3.tgz",
      "integrity": "sha1-TwHhW/2jNS/NjvkEnxPYRIlxolg=",
      "requires": {
        "zrender": "3.1.3"
      }
    },

And change

"zrender": {
      "version": "3.7.0",
      "resolved": "http://registry.npm.taobao.org/zrender/download/zrender-3.1.3.tgz",
      "integrity": "sha1-RFiX5ApDGkIk7w5xNXxh4tdJfIw="
    }

To

"zrender": {
      "version": "3.1.3",
      "resolved": "http://registry.npm.taobao.org/zrender/download/zrender-3.1.3.tgz",
      "integrity": "sha1-RFiX5ApDGkIk7w5xNXxh4tdJfIw="
    }

than rm -rf node_modules && npm install

solution 2: Enforce install the low version echarts and zrender directly:npm install [email protected] && npm install [email protected] Just a temporary solution.

solution3: update your module bundler(eg: use webpack2.0 or webpack3.0 instead webpack1.0)

evagy avatar Nov 09 '17 13:11 evagy

我是用了vue-echarts这个包时报错,查看报错以及node_modules时发现包依赖的echarts的/lib 目录下都是空的,于是我安装了低版本的echarts,用旧版本的lib/整个替换新版本的lib/,然后就正常启动了

linrunzheng avatar Nov 09 '17 14:11 linrunzheng

@YuyangGong thank you for the advice solution 2 worked great! We use eCharts with Gatsby.js so will have to wait until gatsby 2.0 comes out with Webpack3.0 for a long term solution.

Again, thank you for the quick response.

ucanlendit avatar Nov 09 '17 14:11 ucanlendit

@YuyangGong 谢谢大兄弟

aeolusheath avatar Nov 10 '17 02:11 aeolusheath