react-native: React Native Packager sometimes crashes with WebSocket "ERROR not opened"

Description

When developing an app and reloading the iOS simulator, occasionally the react native packager will crash, and I have to restart it.

Here is the output from my console:

Bundling `index.ios.js`
  No module changed.
Bundling `index.ios.js`
  No module changed.
Bundling `index.ios.js`
  No module changed.
 ERROR  not opened
Error: not opened
    at WebSocket.send (/Users/ndbroadbent/code/myapp/node_modules/ws/lib/WebSocket.js:219:16)
    at Server.packagerServer.setHMRFileChangeListener [as _hmrFileChangeListener] (/Users/ndbroadbent/code/myapp/node_modules/react-native/local-cli/server/util/attachHMRServer.js:149:21)
    at Server.onFileChange (/Users/ndbroadbent/code/myapp/node_modules/react-native/packager/react-packager/src/Server/index.js:406:12)
    at Server.processFileChange (/Users/ndbroadbent/code/myapp/node_modules/react-native/packager/react-packager/src/Server/index.js:236:40)
    at Array.forEach (native)
    at HasteMap.dependencyGraph.getWatcher.on (/Users/ndbroadbent/code/myapp/node_modules/react-native/packager/react-packager/src/Server/index.js:261:40)
    at emitOne (events.js:101:20)
    at HasteMap.emit (events.js:188:7)
    at Timeout.emitChange [as _repeat] (/Users/ndbroadbent/code/myapp/node_modules/jest-haste-map/build/index.js:558:14)
    at Timeout.wrapper [as _onTimeout] (timers.js:425:11)

See http://facebook.github.io/react-native/docs/troubleshooting.html
for common problems and solutions.

Reproduction Steps and Sample Code

This happens when I press CMD+R to reload the iOS simulator, but it only happens once every few hours. Sometimes just once a day.

Solution

Catch the error, and just ignore it instead of crashing.

Workaround

I’ve just been running: while true; do react-native start; done

Additional Information

  • React Native version: 0.41.2
  • Platform: iOS
  • Development Operating System: MacOS
  • Dev tools: XCode 8.2.1, iOS 8.4 Simulator.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 80
  • Comments: 55 (2 by maintainers)

Most upvoted comments

i thought the websockets required an error handle but the problem was fixed just by cleaning cache npm start -- --reset-cache

+1 driving me crazy

Don’t worry everyone, they’re aware of the issue, it’s in the code.

    try {
      dest.send(message);
    } catch (e) {
      console.warn(e);
      // Sometimes this call throws 'not opened'
    }
  }

https://github.com/facebook/react-native/blob/0cd69e8a02d254577fac9ccd3ff8a1727a024cc8/local-cli/server/util/webSocketProxy.js#L29

Started to happen to me at 0.49.3

packager does not crash but does have error wx20171009-211945

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community’s attention? This issue may be closed if no further activity occurs. You may also label this issue as “For Discussion” or “Good first issue” and I will leave it open. Thank you for your contributions.

Turn the debugger off. then npm start -- --reset-cache

+1 Me too! It is very irritating because even after I reset the packager’s cache it is still happening. The app is freezing and I cannot press anything until I close it and open it again. Stopping remote JS Debugging didn’t help.

Yes. It usually happened when the debugger was open. Somehow it trigger the action when I’m saving my code but it didn’t rebuilt it using the recent code. When the debugger switched off, it works again.

I’ve made an upgrade from 0.52 to 0.55 and the packager started to print this error with ws. Anyway, I’m using WebSocket for my app to connect the server and it works fine. Nothing happen except printing the error to the packager.

For me, it doesn’t crash, but hot reload and even manual reload stops working until I restart the packager.

Still getting this. Here is my setup:

XCode: 8.3.3
RN 0.50.3
Node 7.5.0

It doesn’t seem to be causing problems but it does print out a new error in my packager every time I reload the app.

In my case it happened after I had babel import aliases in .babelrc

{
  "presets": ["react-native"],
  "plugins": [
    ["module-resolver", {
      "root": ["./src"],
      "alias": {
        "@App": "./src/App.js"
      }
    }]
  ]
}

if i remove it, the problem disappear.

in my case the problem doesn’t affect the code update when hot/manual reloading, it just gives me a error in the terminal.

@ivorscott suggestion didn’t resolve the error for me.

yes i notice that when this error starts popping out, my hot reload aren’t working anymore and I have to literally stop the packager, and rebuild again. Else I will always be shown the same app before the changes. To some extend, I have to delete the app in the simulator and run again.

@jd20 We ran into a similar issue along with other issue(signing, linker, …) with xcode 9. We got around this by reinstalling xcode 8.3.3. Like Magic the issue went away. So unless you/anyone really needs xcode 9 I would suggest reverting until apple works some of the kinks out.

Update: My solution worked my teams case so it might not work for everyone. It’s seems that this is a common issue with multiple answers. If mine does not work I do apologize!