?. 语法报错

报错

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、重启项目

相关推荐
渣哥16 分钟前
多环境配置利器:@Profile 在 Spring 项目中的实战价值
javascript·后端·面试
U.2 SSD34 分钟前
Echart仪表盘示例
javascript·echarts
qq_18417767736 分钟前
前端自动部署项目到服务器
服务器·前端·javascript
Never_Satisfied43 分钟前
在JavaScript / HTML / Node.js中,post方式的Content-Type属性的text的三种编码
javascript·node.js·html
Never_Satisfied1 小时前
在JavaScript / HTML中,Chrome报错Refused to execute inline script
javascript·chrome·html
敲代码的嘎仔1 小时前
JavaWeb零基础学习Day2——JS & Vue
java·开发语言·前端·javascript·数据结构·学习·算法
Keepreal4962 小时前
pdf文件预览实现
javascript·react.js
Asort2 小时前
JavaScript设计模式(九)——装饰器模式 (Decorator)
前端·javascript·设计模式
Man2 小时前
🔥 Vue3 动态 ref 黑科技:一招解决 v-for 中的组件引用难题!
前端·vue.js
叫我少年2 小时前
Vue3 集成 VueRouter
vue.js