ReactNative报错:Development server returned response error code: 500

项目初始化红屏的看过来!!!

出现首行报错 Development server returned response error code: 500

接着出现错误信息里面有类似的:

1

2

3

The development server returned response error code: 500

 

URL: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false

1

2

3

4

error: bundling failed: Error: 

Unable to resolve module ./../react-transform-hmr/lib/index.js from /Users/sturm/Desktop/testpro/App.js: 

The module ./../react-transform-hmr/lib/index.js could not be found from /Users/sturm/Desktop/testpro/App.js. 

Indeed, none of these files exist:

 

找了一下午加半个早上,终于解决了这个bug.(最后一个是官方0.55.2版本的坑)

  1. 首先上面那个 10.0.0.2:8081的地址是不对的,是手机(!!)本地的地址。

        解决办法: 我用的是真机,摇晃手机会出来一个弹窗,在dev-setting里面设置debug server host & port for device,例如192.168.101:8081(你自己电脑的ip地址!)

   2. gayhub有建议 如下操作:

       npm install --save-dev @babel/runtime

       npm install --save-dev @babel/core

        我也照着做了,但是并没有解决问题,不过估计应该装一下,因为我在init的时候这两项是报过warning的,说缺少这两个dependency

    3. 关键的一步

        关掉你的cmd窗口(其他的内置命令行同理)

        mac 下操作

1

2

3

4

5

6

# Clean cache

  rm -rf $TMPDIR/react-*; rm -rf $TMPDIR/haste-*; rm -rf $TMPDIR/metro-*; watchman watch-del-all

# Start Metro Bundler directly

  react-native start

# Now run 

 `react-native run-android` or `react-native run-ios` in another tab

      window 下操作

1

2

3

4

# Clean cache

react-native start --reset-cache

# new cmd tab

react-native run-android

  上面的那个问题是最新版本的坑。官方挖的

   经过这么几个折腾,终于出现了欢迎界面!

   发现有其他坑的,建议去gayhub去找,还是那里最靠谱。

你可能感兴趣的:(React,Native)