使用 babel-preset-react-native/index.js 的 TransformError
我是 react-native 的新手,正在尝试在屏幕上呈现我的第一个文本.
I'm brand new to react-native, and trying to render my first bit of text on the screen.
当我运行 react-native run-ios
然后点击进入我的示例应用程序时,我看到以下错误:
When I run react-native run-ios
and then click into my sample app, I see the following error:
index.js 确实存在于我的项目中,代码如下:
index.js DOES exist in my project, with the following code:
'use strict';
module.exports = require('./configs/main');
到目前为止,我已经尝试了以下方法:
So far, I have tried the following:
1) 为 babel-preset-react-native 重新安装 npm
1) Re-installing npm for babel-preset-react-native
2) 使用 yarn 删除然后重新添加 babel-preset-react-nativeyarn 移除 babel-preset-react-native
yarn 添加 babel-preset-react-native@2.1.0
2) Using yarn to remove and then re-add babel-preset-react-nativeyarn remove babel-preset-react-native
yarn add babel-preset-react-native@2.1.0
3) 彻底删除 babel.rc
3) Deleting babel.rc entirely
没有任何效果.渴望听取有关其他尝试的建议和建议.
Nothing has worked. Eager to hear advice and suggestions for other things to try.
这是 babel-preset-react-native
新版本中的 bug,因为它会在你运行 后自动添加react-native init
命令
This is bug in the new version of babel-preset-react-native
as it will added automatically after you run react-native init
command
请看一下这个 github 问题 https://github.com/facebook/react-native/issues/15513
Please take a look at this github issue https://github.com/facebook/react-native/issues/15513
解决方法,尝试更改版本:
Workaround, try to change the version:
yarn remove babel-preset-react-native
yarn add babel-preset-react-native@2.1.0
如果这对您不起作用,请尝试在下面的代码中删除 node_modules/babel-preset-react-native/configs/main.js
中的尾随逗号
if that's not work for you, try to remove trailing comma at node_modules/babel-preset-react-native/configs/main.js
at this code below