?. 语法报错

报错

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

相关推荐
放下华子我只抽RuiKe55 小时前
React 从入门到生产(四):自定义 Hook
前端·javascript·人工智能·深度学习·react.js·自然语言处理·前端框架
XinZong5 小时前
OpenClaw 实现双重心跳(Heartbeat)+ clawreach虾聊项目实现
javascript
还有多久拿退休金7 小时前
一张栈的图,治好你面试答不出 script 阻塞的病
前端·javascript
zithern_juejin7 小时前
原型与原型链
javascript
还有多久拿退休金9 小时前
我用 Three.js 造了个 3D 漫步世界,角色走路像喝醉了——以及我是怎么修好的
前端·vue.js
LJA648449 小时前
为什么 AI 时代更需要配置化组件库
vue.js
008爬虫实战录10 小时前
【码上爬】 题十二:如来神掌 困难, JSVMP加密,使用代理补环境
前端·javascript·node.js
threelab10 小时前
Three.js 数学函数着色器 | 三维可视化 / AI 提示词
javascript·人工智能·着色器
ZC跨境爬虫11 小时前
跟着 MDN 学CSS day_3:(为一个传记页面添加样式)
前端·javascript·css·ui·音视频·html5
夜雪闻竹11 小时前
sql.js WASM 实战:浏览器里跑 SQLite
javascript·sql·wasm