question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught SyntaxError: Unexpected token export

See original GitHub issue

引入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 但是还是同样的问题

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
evagycommented, Nov 9, 2017

@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 echarts@3.2.3 && npm install zrender@3.1.3 Just a temporary solution.

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

0reactions
aeolusheathcommented, Nov 10, 2017

@YuyangGong 谢谢大兄弟

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: Unexpected token 'export' in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >
Getting Unexpected Token Export - javascript - Stack Overflow
The problem was that I was changing my code from non-modules to modules and I forgot to delete the imported script file. My...
Read more >
How to Fix „Uncaught SyntaxError: Unexpected token 'export
Using type="module" on the <script> tag solved the „Unexpected token export ” error. The browser runs the imported JavaScript without issues.
Read more >
How to Solve Unexpected Token 'export' Error in JavaScript
To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file.
Read more >
SyntaxError: Unexpected token 'export' - Abhishek Kumar
In case you are getting error like 'Unexpected token export' while starting the server, then export like below in schema.js
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found