【问题标题】:How to install plugin-export-default-from to Babel in react project如何在 React 项目中将 plugin-export-default-from 安装到 Babel
【发布时间】:2019-08-19 10:59:34
【问题描述】:

我在整个过程中不断收到以下错误

SyntaxError: /Users/user1/npmprojects/experiments/test-reactstrap0/src/components/index.js: Support for the experimental syntax 'exportDefaultFrom' isn't currently enabled (15:8):

  13 | export * from './ListItems';
  14 | 
> 15 | export FormField from './FormField';

首先我安装插件:yarn add @babel/plugin-proposal-export-default-from --save-dev

我也试过安装yarn add babel-preset-stage-1 --save-dev

我尝试添加一个包含内容的 .babelrc 文件

{
  "plugins": [
    "@babel/plugin-proposal-export-default-from"
  ]
}

我尝试将以下内容添加到我的 package.json 中

"babel": {
    "presets": [
    "es2015",
    "stage-1",
    "react"
  ],
  "plugins": [
    "@babel/plugin-proposal-export-default-from"
  ]
}

【问题讨论】:

    标签: reactjs babeljs ecmascript-2017


    【解决方案1】:

    您可以将配置放入您的babelrc.js 文件中:

    module.exports = {
      plugins: [
        "@babel/plugin-proposal-export-default-from"
      ]
    }
    

    babelbabel-loader for Webpack 等工具将从此处获取配置。

    祝你好运……

    【讨论】:

    • 似乎不起作用。你测试过这个吗?
    • 嗨@Sisir,是的,当我在我的一个项目中使用它时,它可以工作。
    【解决方案2】:

    Babel 中有一个未解决的问题:https://github.com/babel/babel/issues/7293

    看起来您还需要安装 @babel/plugin-proposal-export-namespace-from 插件,但不是 100% 确定,最好通读问题讨论并尝试建议的解决方法。

    【讨论】:

      猜你喜欢
      • 2020-09-16
      • 2019-08-04
      • 2017-04-23
      • 2018-06-06
      • 2019-03-05
      • 1970-01-01
      • 2019-11-26
      • 2018-10-26
      • 2022-09-23
      相关资源
      最近更新 更多