【问题标题】:How to add Babel support for nullishCoalescingOperator to vue project?如何在 vue 项目中添加对 nullishCoalescingOperator 的 Babel 支持?
【发布时间】:2020-07-04 12:40:56
【问题描述】:

在我的 Vue-CLI 项目中,当我尝试使用 ?? 运算符时,我收到了这个错误:

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

...

将 @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);

我做错了什么?

【问题讨论】:

    标签: babeljs vue-cli babel-plugin


    【解决方案1】:

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

    我必须使用错误消息建议您使用的 @babel/plugin-proposal-nullish-coalescing-operator 插件。

    另外,我在page for the @babel/plugin-syntax-nullish-coalescing-operator plugin:上注意到了这一点

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

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 2020-01-02
      • 1970-01-01
      • 2016-05-07
      • 2022-11-09
      相关资源
      最近更新 更多