Uncaught SyntaxError: Unexpected token export
See original GitHub issue引入echarts 导致,访问前段项目报错,如下图。
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:
- Created 6 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
To
And change
To
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)
@YuyangGong 谢谢大兄弟