echarts报错Uncaught SyntaxError: Unexpected token ‘<‘

在尝试使用echarts时遇到Uncaught SyntaxError:Unexpected token '<'的问题。通过按照官方教程操作并参考其他博主的建议,发现需要完整下载echarts的js文件,而不仅仅是单一文件。通过在线定制并下载所有组件,问题得到解决。
摘要由CSDN通过智能技术生成

问题重现

最近需要研究echarts做图表,打算在html中先引用echarts试试。

于是百度到echarts官网的教程:5 分钟上手 ECharts

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="echarts.min.js"></script>
</head>
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width: 600px;height:400px;"></div>
    <script type="text/javascript">
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var option = {
    
            title: {
    
                text: 'ECharts 入门示例'
            },
            tooltip: {
    },
            legend: {
    
                data:['销量']
            },
            xAxis: {
    
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {
    },
            series: [{
    
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>
</html>

从教程中看到只在html中引用了echarts.min.js,打算将echarts.min.js下载到本地,然后我在
https://echarts.apache.org/zh/download.html
点击了最新的5.0.2 Dist,跳转到
https://github.com/apache/echarts/tree/5.0.2/dist
下载了echarts.min.js,放到了springboot项目下的static/js/echarts/,如下图。
在这里插入图片描述
启动项目浏览器中进入页面,控制台报错

Uncaught SyntaxError: Unexpected token '<'

在这里插入图片描述
什么鬼,我明明按教程做的,页面代码也是复制的,最多就是js引用路径不同,直接在浏览器输入js的路径也正常。
在这里插入图片描述
查了百度,应该是缺少东西,后面看到一位博主
EChart 学习笔记一:EChart在html中的使用方式。
文中提到在线定制,我才知道有这样的东西…
在这里插入图片描述
我把最后的代码压缩取消勾选了,上面的所有组件全都选了,打包下载的提示是

Loaded module: "/echarts@5.0.2/lib/echarts.js"
Loaded module: "/echarts@5.0.2/lib/export/core.js"
Loaded module: "/echarts@5.0.2/lib/core/echarts.js"
Loaded module: "/tslib@2.0.3/tslib.es6.js"
Loaded module: "/zrender@5.0.4/lib/zrender.js"
Loaded module: "/zrender@5.0.4/lib/core/env.js"
Loaded module: "/zrender@5.0.4/lib/core/util.js"
Loaded module: "/zrender@5.0.4/lib/Handler.js"
Loaded module: "/zrender@5.0.4/lib/core/vector.js"
Loaded module: "/zrender@5.0.4/lib/mixin/Draggable.js"
Loaded module: "/zrender@5.0.4/lib/core/Eventful.js"
Loaded module: "/zrender@5.0.4/lib/core/event.js"
Loaded module: "/zrender@5.0.4/lib/core/dom.js"
Loaded module: "/zrender@5.0.4/lib/core/fourPointsTransform.js"
Loaded module: "/zrender@5.0.4/lib/core/GestureMgr.js"
Loaded module: "/zrender@5.0.4/lib/Storage.js"
Loaded module: "/zrender@5.0.4/lib/Element.js"
Loaded module: "/zrender@5.0.4/lib/core/Transformable.js"
Loaded module: "/zrender@5.0.4/lib/core/matrix.js"
Loaded module: "/zrender@5.0.4/lib/animation/Animator.js"
Loaded module: "/zrender@5.0.4/lib/animation/Clip.js"
Loaded module: "/zrender@5.0.4/lib/animation/easing.js"
Loaded module: "/zrender@5.0.4/lib/tool/color.js"
Loaded module: "/zrender@5.0.4/lib/core/LRU.js"
Loaded module: "/zrender@5.0.4/lib/core/BoundingRect.js"
Loaded module: "/zrender@5.0.4/lib/core/Point.js"
Loaded module: "/zrender@5.0.4/lib/contain/text.js"
Loaded module: "/zrender@5.0.4/lib/config.js"
Loaded module: "/zrender@5.0.4/lib/core/timsort.js"
Loaded module: "/zrender@5.0.4/lib/animation/Animation.js"
Loaded module: "/zrender@5.0.4/lib/animation/requestAnimationFrame.js"
Loaded module: "/zrender@5.0.4/lib/dom/HandlerProxy.js"
Loaded module: "/zrender@5.0.4/lib/graphic/Group.js"
Loaded module: "/echarts@5.0.2/lib/model/Global.js"
Loaded module: "/echarts@5.0.2/lib/util/model.js"
Loaded module: "/echarts@5.0.2/lib/util/number.js"
Loaded module: "/echarts@5.0.2/lib/util/log.js"
Loaded module: "/echarts@5.0.2/lib/model/Model.js"
Loaded module: "/echarts@5.0.2/lib/util/clazz.js"
Loaded module: "/echarts@5.0.2/lib/model/mixin/areaStyle.js"
Loaded module: "/echarts@5.0.2/lib/model/mixin/makeStyleMapper.js"
Loaded module: "/echarts@5.0.2/lib/model/mixin/textStyle.js"
Loaded module: "/echarts@5.0.2/lib/label/labelStyle.js"
Loaded module: "/zrender@5.0.4/lib/graphic/Text.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/parseText.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/image.js"
Loaded module: "/zrender@5.0.4/lib/graphic/TSpan.js"
Loaded module: "/zrender@5.0.4/lib/graphic/Displayable.js"
Loaded module: "/zrender@5.0.4/lib/graphic/Path.js"
Loaded module: "/zrender@5.0.4/lib/core/PathProxy.js"
Loaded module: "/zrender@5.0.4/lib/core/bbox.js"
Loaded module: "/zrender@5.0.4/lib/core/curve.js"
Loaded module: "/zrender@5.0.4/lib/contain/path.js"
Loaded module: "/zrender@5.0.4/lib/contain/line.js"
Loaded module: "/zrender@5.0.4/lib/contain/cubic.js"
Loaded module: "/zrender@5.0.4/lib/contain/quadratic.js"
Loaded module: "/zrender@5.0.4/lib/contain/arc.js"
Loaded module: "/zrender@5.0.4/lib/contain/util.js"
Loaded module: "/zrender@5.0.4/lib/contain/windingLine.js"
Loaded module: "/zrender@5.0.4/lib/graphic/Image.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Rect.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/roundRect.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/subPixelOptimize.js"
Loaded module: "/echarts@5.0.2/lib/util/states.js"
Loaded module: "/echarts@5.0.2/lib/util/innerStore.js"
Loaded module: "/echarts@5.0.2/lib/util/graphic.js"
Loaded module: "/zrender@5.0.4/lib/tool/path.js"
Loaded module: "/zrender@5.0.4/lib/tool/transformPath.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Circle.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Ellipse.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Sector.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/roundSector.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Ring.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Polygon.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/poly.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/smoothSpline.js"
Loaded module: "/zrender@5.0.4/lib/graphic/helper/smoothBezier.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Polyline.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Line.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/BezierCurve.js"
Loaded module: "/zrender@5.0.4/lib/graphic/shape/Arc.js"
Loaded module: "/zrender@5.0.4/lib/graphic/CompoundPath.js"
Loaded module: "/zrender@5.0.4/lib/graphic/LinearGradient.js"
Loaded module: "/zrender@5.0.4/lib/graphic/Gradient.js"
Loaded module:
在Vue项目中,当在引入第三方依赖的JS文件时,可能会遇到报错信息"Uncaught SyntaxError: Unexpected token <"。这个错误通常是由于引入的JS文件路径错误导致的。在控制台中会提示这个错误,并且指出具体的文件和位置。 根据引用中的描述,可能是因为在index.html文件中引入的JS文件路径不正确。原本的JS文件应该放在/src/utils文件夹下,但是引入的路径却是/src和/static。这种情况下,浏览器会认为引入的是一个HTML文件而不是JS文件,从而导致了"Uncaught SyntaxError: Unexpected token <"的错误。 解决这个问题的方法是确保引入的JS文件的路径是正确的。可以检查index.html文件,确保引入的路径与实际文件所在的路径相匹配。将路径修改为/src/utils文件夹下的JS文件路径即可避免这个错误的发生。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue项目报错Uncaught SyntaxError: Unexpected token <](https://download.csdn.net/download/weixin_38593823/12949934)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Vue项目报错Uncaught SyntaxError: Unexpected token](https://download.csdn.net/download/weixin_38697328/14820887)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [浏览器显示数据库中数据的条形图柱状图 前后端分离vue.js+spring boot 计算机软件工程课程设计毕业设计 ...](https://download.csdn.net/download/Amzmks/88275824)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值