更新时间:2022-06-22 03:11:45
update: for RN >0.59 正如@RedGaint 在 https://***.com/a/55134051/8034782 你需要在root级别配置metro.config.js
.
update: for RN >0.59 as @RedGaint pointed in https://***.com/a/55134051/8034782 you need to configure metro.config.js
in the root level.
module.exports = {
resolver: {
/* resolver options */
sourceExts: ['jsx','js'] //add here
},
transformer: {
/* transformer options */
},
serializer: {
/* serializer options */
},
server: {
/* server options */
}
/* general options */
};
对于 RN :在项目的根目录中添加一个名为 rn-cli.config.js 的文件,并将以下代码放入其中.
For RN < 0.57: Inside of the root of your project add a file named rn-cli.config.js and place the following code into it.
// ./rn-cli.config.js
module.exports = {
/// @description Allows you to enable support for JSX files
/// The `index.js` file in the root of your project has to be `.js`.
getSourceExts: () => [ 'jsx', 'js' ],
}
对于 RN > 0.57:
module.exports = {
resolver: {
sourceExts: ['jsx', 'js'],
},
};
有关此问题的更多参考,已经打开了一个问题:
for more reference look into this there is already an issue opened:
https://github.com/facebook/react-native/pull/5233#issuecomment-382083236