简体   繁体   English

将 @babel/preset-react (https://git.io/JfeDR) 添加到 Babel 配置的“预设”部分以启用转换

[英]Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation

I am new in react-native and Im adding babel on my project.我是 react-native 的新手,我在我的项目中添加了 babel。 I have a function that returns a component.我有一个返回组件的 function。

But I am getting this error但我收到了这个错误

on my function在我的 function

const renderComponent = () => {
   return (
     <View>
      ....
     </View>

}

在此处输入图像描述

on my babel.config.js在我的 babel.config.js 上

// const path = require('path');

require('dotenv').config();

const { NODE_ENV } = process.env;
console.log(__dirname);

const DEFAULT_PLUGINS = [
  'module:react-native-dotenv',
  '@babel/plugin-transform-react-jsx',
  '@babel/plugin-transform-react-display-name',
  '@babel/plugin-syntax-jsx'
];

module.exports = function (api) {
  const presets = [
    'module:metro-react-native-babel-preset',
    'react',
    'react-native',
    '@babel/preset-react',
  ];
  const plugins = NODE_ENV === 'development'
    ? DEFAULT_PLUGINS
    : [...DEFAULT_PLUGINS, 'transform-remove-console'];

  api.cache(false);

  return {
    presets,
    plugins
  };

};

what's wrong on my setup.我的设置有什么问题。 Thank you!谢谢!

I'm a react-native-dotenv maintainer.我是react-native-dotenv维护者。 The library is no longer a preset.库不再是预设。 It should be moved to plugins.它应该移动到插件中。

I renamed my babel.config.js to .babelrc and added following code.我将我的babel.config.js重命名为.babelrc并添加了以下代码。 It worked!有效!

{
"presets": [
"@babel/preset-env",
["@babel/preset-react"]
]
}

暂无
暂无

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

相关问题 React - 将 @babel/preset-react (https://git.io/JfeDR) 添加到 Babel 配置的“预设”部分以启用转换 - React - Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation 将 @babel/plugin-proposal-class-properties (https://git.io/vb4SL) 添加到 Babel 配置的“插件”部分以启用转换 - Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation 如何将 @babel/preset-react 添加到 babel.config.js 的预设部分 - How do I add @babel/preset-react to the presets section of babel.config.js 在 babel 中预设反应和反应之间的区别 - difference between preset-react and react in babel 从反应库导入后出现“添加@babel/preset-react...”错误 - "Add @babel/preset-react ..." error after importing from a react library 解析错误:找不到模块“@babel/preset-react” - Parsing error: Cannot find module '@babel/preset-react' 在Webpack中配置Babel-preset-stage-0 - Config Babel-preset-stage-0 in Webpack babel问题反应预设和反应dom - problems with babel react preset and react-dom 使用带有babel和babel-preset-react和babel-preset-es2015的webpack - Using webpack with babel and babel-preset-react and babel-preset-es2015 尽管使用了babel-preset-react,babel-preset-es2015和babel-preset-stage-3,browserify无法解析jsx - browserify fails to parse jsx despite using babel-preset-react, babel-preset-es2015 and babel-preset-stage-3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM