?. 语法报错

报错

Syntax Error: SyntaxError: E:xxx\src\views\xxx.vue: Support for the experimental syntax 'optionalChaining' isn't currently enabled (173:27):

171 | label: node.label,

172 | style: {

173 | fill: colorSet?.mainFill || '#DEE9FF',

| ^

174 | stroke: colorSet?.mainStroke || '#5B8FF9',

175 | },

176 | labelCfg: {

Add @babel/plugin-proposal-optional-chaining (https://git.io/vb4Sk) to the 'plugins' section of your Babel config to enable transformation.

原因

控制台也提示了,缺个语法解析的包 @babel/plugin-proposal-optional-chaining

解决办法

1、yarn add @babel/plugin-proposal-optional-chaining

2、babel.config.js中添加 plugins,如下:

javascript 复制代码
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)


const plugins = ['@babel/plugin-proposal-optional-chaining']
if (IS_PROD) {
  plugins.push('transform-remove-console')
}


// lazy load ant-design-vue
// if your use import on Demand, Use this code
plugins.push([
  'import',
  {
    libraryName: 'ant-design-vue',
    libraryDirectory: 'es',
    style: true, // `style: true` 会加载 less 文件
  },
])


module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
    [
      '@babel/preset-env',
      {
        useBuiltIns: 'entry',
        corejs: 3,
      },
    ],
  ],
  plugins,
}

3、重启项目

相关推荐
LateFrames4 分钟前
使用 Winform / WPF / WinUI3 / Electron 实现异型透明窗口
javascript·electron·wpf·winform·winui3
Asort8 分钟前
React类组件精要:定义机制与生命周期方法进阶教程
前端·javascript·react.js
陳陈陳9 分钟前
从“变量提升”到“调用栈爆炸”:V8 引擎是如何偷偷执行你的 JavaScript 的?
javascript
小二·14 分钟前
从零到上线:Spring Boot 3 + Spring Cloud Alibaba + Vue 3 构建高可用 RBAC 微服务系统(超详细实战)
vue.js·spring boot·微服务
San3016 分钟前
深入理解JavaScript执行机制:从变量提升到内存管理
javascript·编程语言·代码规范
用户120391129472617 分钟前
深入理解JavaScript执行机制:从变量提升到调用栈全解析
javascript
weixin_4386943928 分钟前
pnpm 安装依赖后 仍然启动报的问题
开发语言·前端·javascript·经验分享
烟袅1 小时前
深入 V8 引擎:JavaScript 执行机制全解析(从编译到调用栈)
前端·javascript
有点笨的蛋1 小时前
JavaScript 执行机制深度解析:编译、执行上下文、变量提升、TDZ 与内存模型
前端·javascript
_一两风1 小时前
深入理解JavaScript执行机制:从一道经典面试题说起
javascript