如何在vue项目中添加对nullishCoalescingOperator的Babel支持?

时间:2020-03-24 01:52:22

标签: babeljs vue-cli babel-plugin

在我的Vue-CLI项目中,当我尝试使用??运算符时,出现了以下错误:

语法错误:SyntaxError:/Users/stevebennett/odev/freelancing/v-map/src/components/Map.vue:>当前未启用对实验语法'nullishCoalescingOperator'的支持(30:29):< / p>

...

将@ babel / plugin-proposal-nullish-coalescing-operator(https://git.io/vb4Se)添加到Babel配置的“插件”部分,以启用转换。

我安装了@ babel / plugin-syntax-nullish-coalescing-operator(它的名称似乎已更改),并将其添加到babel.config.js中:

module.exports = {
    presets: ['@vue/app'],
    plugins: ['@babel/plugin-syntax-nullish-coalescing-operator'],
};

现在错误消息似乎已经倒退了,根本没有引用操作员名称:

Module parse failed: Unexpected token (39:35)
You may need an appropriate loader to handle this file type.
|             case 8:
|               points = _context.sent;
               console.log(sheetID ?? 37);

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

对我来说,@babel/plugin-syntax-nullish-coalescing-operator 插件不起作用,这就是您正在使用的那个。

我不得不使用 @babel/plugin-proposal-nullish-coalescing-operator 插件,这是错误消息建议您使用的插件。

此外,我在 page for the @babel/plugin-syntax-nullish-coalescing-operator plugin:

上注意到了这一点

enter image description here

我不能肯定这是否能解决您的问题,但它确实解决了我的问题

相关问题