代码之家  ›  专栏  ›  技术社区  ›  Steve Bennett

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

  •  0
  • Steve Bennett  · 技术社区  · 6 年前

    在我的Vue CLI项目中,当我尝试使用 ?? 接线员,我有个错误:

    语法错误:SyntaxError:/Users/stevenbennett/odev/freelancing/v-map/src/components/map。vue:>当前未启用对实验语法“nullishCoalescingOperator”的支持(30:29):

    ...

    添加@babel/plugin建议nullish合并运算符( https://git.io/vb4Se )转到Babel配置的“插件”部分以启用转换。

    我安装了@babel/plugin语法nullish coalescing操作符(它的名称似乎已经更改),并将其添加到我的babel中。配置。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);
    

    我做错了什么?

    0 回复  |  直到 6 年前
        1
  •  1
  •   Fearnbuster    5 年前

    对我来说 @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

    我不能肯定这是否能解决你的问题,但它肯定能解决我的问题

    推荐文章
    Brock  ·  Vue-Vue CLI-API变量
    9 年前