[英]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.