简体   繁体   English

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

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

I get this error "React - Add @babel/preset-react ( https://git.io/JfeDR ) to the 'presets' section of your Babel config to enable transformation"我收到此错误“React - 将 @babel/preset-react ( https://git.io/JfeDR ) 添加到 Babel 配置的 'presets' 部分以启用转换”

This is the presets section from my babel.config.js:这是我的 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),

Try:尝试:

],
  (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)

If I am not mistaken, bundle exec rails webpacker:install:react will add that bit to the babel.config.js如果我没记错的话, bundle exec rails webpacker:install:react会将该位添加到babel.config.js

Here is some useful information which helped me a while back to set up webpacker properly: https://github.com/rails/webpacker/blob/v4.3.0/docs/webpack.md这里有一些有用的信息帮助我正确设置 webpacker: https://github.com/rails/webpacker/blob/v4.3.0/docs/webpack.md

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

相关问题 如何将“ babel-preset-stage-2”加载程序添加到rails / webpacker / vue应用程序? - How to add “babel-preset-stage-2” loader to a rails/webpacker/vue app? Babel如何忽略jQuery - Babel How to ignore jquery React / Babel:组件不只在CircleCI上渲染 - React/Babel: Components not rendering only on CircleCI Webpack 编译:部署生产时找不到模块“@babel/preset-env” - Webpack Compile: Cannot find module '@babel/preset-env' when deploy production 为什么我会收到此错误:模块构建失败(来自./node_modules/babel-loader/lib/index.js):语法错误意外令牌,预期“,” - Why am I getting this error: Module build failed (from ./node_modules/babel-loader/lib/index.js): Syntax Error Unexpected token, expected "," 使用Rails 4.2.4 / React 0.14.6和Devise 4.0 / babel-core 6.7.4 / webpack 1.12.14缺少模板 - Template is missing using Rails 4.2.4/React 0.14.6 and Devise 4.0/babel-core 6.7.4/webpack 1.12.14 使用Rails 5 Webpacker设置babel插件 - Setup babel plugin with Rails 5 webpacker 在运行单元测试时,如何添加React作为全局变量? - How do I add React as a global whilst running unit tests? 如何在React-Rails中向表单添加动作? - How do I add an action to a form in React-Rails? 如何在 Rails 6 中将我的 Ngrok 隧道动态添加到 config.hosts? - How do I dynamically add my Ngrok tunnel to config.hosts in Rails 6?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM