繁体   English   中英

如何将 @babel/preset-react 添加到 babel.config.js 的预设部分

[英]How do I add @babel/preset-react to the presets section of babel.config.js

我收到此错误“React - 将 @babel/preset-react ( https://git.io/JfeDR ) 添加到 Babel 配置的 'presets' 部分以启用转换”

这是我的 babel.config.js 中的预设部分:

    presets: [
  isTestEnv && [
    '@babel/preset-env',
    {
      targets: {
        node: 'current'
      }
    }
  ],
  (isProductionEnv || isDevelopmentEnv) && [
    '@babel/preset-env',
    {
      forceAllTransforms: true,
      useBuiltIns: 'entry',
      corejs: 3,
      modules: false,
      exclude: ['transform-typeof-symbol']
    }
  ]
].filter(Boolean),

尝试:

],
  (isProductionEnv || isDevelopmentEnv) && [
    '@babel/preset-env',
    {
      forceAllTransforms: true,
      useBuiltIns: 'usage',
      corejs: '3',
      modules: false,
      exclude: ['transform-typeof-symbol']
    }
  ],
  [
    '@babel/preset-react',
    {
      development: isDevelopmentEnv || isTestEnv,
      useBuiltIns: true
    }
  ]
].filter(Boolean)

如果我没记错的话, bundle exec rails webpacker:install:react会将该位添加到babel.config.js

这里有一些有用的信息帮助我正确设置 webpacker: https://github.com/rails/webpacker/blob/v4.3.0/docs/webpack.md

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM