Zsan
Zsan
  • 发布:2022-07-23 16:29
  • 更新:2023-12-15 10:47
  • 阅读:1280

【报Bug】编译器无法编译ES6的 可选链式运算符 ?.

分类:HBuilderX

产品分类: HbuilderX

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 12.2.1

HBuilderX版本号: 3.4.18

示例代码:
<script>  
    export default {  
        data() {  
            return {  
                title: 'Hello'  
            }  
        },  
        onLoad() {  
            if(this.title?.value) console.log(this.title.value)  
        },  
        methods: {  

        }  
    }  
</script>

操作步骤:

hbuilderx新建uniapp项目,使用?.可选链式运算符,编译报错

预期结果:

可以使用?.可选链式运算符

实际结果:

报错 SyntaxError: Unexpected token .

bug描述:

项目中使用?.可选链式运算符,编译报错 SyntaxError: Unexpected token .

2022-07-23 16:29 负责人:DCloud_UNI_Anne 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

未复现此问题,请升级至HBuilder X3.5.2-alpha试下

  • Zsan (作者)

    重新安装使用Hbuilder X 3.5.2.20220719-alpha 依然报错

    2022-07-26 08:40

  • DCloud_UNI_Anne

    回复 Zsan: 运行到哪个平台?

    2022-07-26 11:53

  • Zsan (作者)

    回复 DCloud_UNI_Anne: 尝试了h5、微信小程序、app都编译不通过

    2022-07-27 10:12

  • Zsan (作者)

    回复 DCloud_UNI_Anne: 我尝试使用在cli项目运行,是可以编译成功的,但是用HbuilderX内置的编译器却无法通过

    2022-07-27 10:16

Zsan

Zsan (作者)

这是运行的项目

2***@qq.com

2***@qq.com

相同问题

console.log(res?.data)

立马报错,而且还不报堆栈,太不友好了,找了半天才找到是可选链问题。

16:56:12.495 SyntaxError: Unexpected token .  
16:56:12.505 [hmr] Failed to reload /src/pages/home.vue. This could be due to syntax errors or importing non-existent modules. (see errors above)  
16:56:12.520 Uncaught (in promise)TypeError: Cannot destructure property `default` of 'undefined' or 'null'.  
    at hot.accept (http://localhost:3000/src/pages/home.vue?import&t=1668329765247:80:24)  
    at acceptDeps (http://localhost:3000/@vite/client:519:60)  
    at http://localhost:3000/@vite/client:461:13  
    at forEach (http://localhost:3000/@vite/client:350:60)  
    at Array.forEach (<anonymous>)  
    at queueUpdate (http://localhost:3000/@vite/client:350:38)  

MAC系统11.1
HBuilderX 3.6.4.20220922
vue3项目

  • 2***@qq.com

    就连

    class EventEmiter {

    _events = {};

    }


    都报错,我也是非常服


    SyntaxError: Unexpected token =

    2022-11-13 17:12

  • DCloud_UNI_Anne

    回复 2***@qq.com: 运行到哪个平台?

    2022-11-14 18:14

a***@qq.com

a***@qq.com

兄弟问题解决了吗,相同问题

报错: SyntaxError: Unexpected token =

报错代码 -----------------------------------------
async testReserve() {
const a = {
b: "xxx"
}
console.log(a.c?.d, "测试")
},

2***@qq.com

2***@qq.com

兄弟解决了吗 ?

BeforeMount

BeforeMount

解决了吗

  • DCloud_UNI_Anne

    哪个端?用HBuilder最新版本,上面示例项目跑下看是否正常?

    2023-12-01 20:48

easyang

easyang

同样的问题我也报错了,之前好好的,突然后面就一直报错了,不过chrome、和小程序运行都正常,就内置浏览器提示“连接服务器超时,点击屏幕重试”,最新版hbuilerx 3.98,系统版本:maxos 14.2

这句代码报错<text style="color: black; font-size: 40rpx;">{{appInfo?.appName}}</text>
把上面的修改成<text style="color: black; font-size: 40rpx;">{{appInfo.appName}}</text>才能正常

报错日志:
[广告] 10:39:31.600 DCloud招聘,欢迎前端、Node、Android、iOS工程师来投简历! 详情点击
10:39:31.622 项目 'test' 开始编译...
10:39:31.643 [vite] server connection lost. polling for restart...
10:39:32.706 请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。
10:39:32.711 正在编译中...
10:39:33.660 编译器版本:3.98(vue3)
10:39:33.665 vite v4.2.1 dev server running at:
10:39:33.666 - Local: http://localhost:5173/
10:39:33.672 * Network: http://192.168.31.112:5173/
10:39:33.682 - Network: http://192.168.64.1:5173/
10:39:33.689 项目 'test' 编译成功。前端运行日志,请另行在浏览器的控制台查看。
10:39:33.689 点击控制台右上角debug图标(虫子),可开启断点调试(添加断点:双击编辑器行号添加断点)
10:39:33.695 H5版常见问题参考: https://ask.dcloud.net.cn/article/35232
10:39:33.695 ready in 1485ms.
10:39:34.379 [vite] connecting...
10:39:34.409 [vite] connected.
10:39:34.743 [Vue warn]: Unhandled error during execution of async component loader
at <AsyncComponentWrapper>
at <PageBody>
at <Page>
at <Anonymous>
at <KeepAlive>
at <RouterView>
at <Layout>
at <App>
10:39:34.748 SyntaxError: Unexpected token . at @fs/Applications/HBuilderX.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-h5-vue/dist/vue.runtime.esm.js:1442

要回复问题请先登录注册