优快云上有人给出了解决方案,我项目跟他类似,也是0.57.5版本的RN项目
https://blog.youkuaiyun.com/u012852597/article/details/82696226
官方解决问题记录是在:https://github.com/facebook/react-native/issues/20791
有人说这是0.57.0-rc2的问题,在rc3里已经解决了。
但我的版本是0.57.5还是出现了,所以这个解释应该不适合我。
以下是别人的解决成功的方案:
一、可以试试
react-native start --reset-cache
报如下错误
warning: the transform cache was reset.
Loading dependency graph...events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8081
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1355:14)
at listenInCluster (net.js:1396:12)
at Server.listen (net.js:1480:7)
at F:\Git\xxx\xxx\node_modules\metro\src\index.js:193:18
at new Promise (<anonymous>)
at Object.<anonymous> (F:\Git\xxx\xxx\node_modules\metro\src\index.js:192:12)
at Generator.next (<anonymous>)
at step (F:\Git\xxx\xxx\node_modules\metro\src\index.js:50:30)
看错误信息,是端口被占用,想到node还开着,就先关掉。
再次运行
react-native start --reset-cache
再重新运行项目
问题依旧,这个方案没能解决我的问题。

思路:
感觉像是版本升级导致的问题。
二、可以试试
https://github.com/facebook/react-native/issues/20791#issuecomment-415986358
解决办法的步骤
1* Make sure the you put rc.3 in your package.json
2* Delete `package-lock.json`
3* Delete `node_modules`
4* `npm i`
5* `react-native start --reset-cache`
或许作者自己的问题解决了,但别人用他的方式去解决,问题依旧。
乖乖,我最终的解决方案
修改.babelrc文件,我的文件内容是
{
"presets": ["react-native"]
}
在0.57版本之后,应该改成
{
"presets": ["module:metro-react-native-babel-preset"]
}
https://github.com/facebook/react-native/issues/20791#issuecomment-416419366
最后运行成功。
方法千万种,别放弃,耐心点,一样一样的尝试,总有一种适合自己的解决办法,多做些记录,给后来者参考。
本文详细记录了在React Native 0.57.x版本中遇到的项目启动问题及其解决过程。通过调整.babelrc文件中的preset设置,成功解决了因版本升级引发的启动难题。
552

被折叠的 条评论
为什么被折叠?



