Cannot read property 'code' of undefined
See original GitHub issueDescription
When you turn off Metro bundler while the app is running, two toasts appear:
- Cannot connect to Metro (warning)
- Cannot read property ‘code’ of undefined (error)
The warning is expected but the error is not.
The issue can be reproduced on a fresh RN 0.71.0-rc.2 app.
Version
0.71.0-rc.2
Output of npx react-native info
System:
OS: macOS 12.6
CPU: (8) arm64 Apple M1 Pro
Memory: 94.03 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.11.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.2 - /opt/homebrew/bin/npm
Watchman: 2022.10.31.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK:
API Levels: 26, 28, 29, 30, 31, 32, 33
Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0
System Images: android-28 | Google APIs ARM 64 v8a, android-28 | Google ARM64-V8a Play ARM 64 v8a, android-33 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.11 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.0.0-20221129-2018-43027b6d4 => 0.0.0-20221129-2018-43027b6d4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
- Initialize a fresh RN app
- Start Metro bundler
- Launch React Native app
- Close Metro bundler
- Watch the red toast appear
Snack, code example, screenshot, or link to a repository


Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top Results From Across the Web
Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined ... Undefined means that a variable has been declared but has not been assigned a...
Read more >JS/Ionic:TypeError: Cannot read property 'code' of undefined
The error I am getting is: TypeError: Cannot read property 'code' of undefined at services.js:65 What should I do to solve this error?...
Read more >Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >Cannot read property 'Code' of undefined · Issue #2861 · aws ...
Describe the bug Periodically, when an SqsClient sends a ReceiveMessageCommand I receive: TypeError: Cannot read property 'Code' of ...
Read more >How to Prevent the Error: Cannot Read Property '0' of Undefined
Check your Code for Common Mistakes · Check for Undefined Before Accessing the Array · Provide an Alternative Value When the Array is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for reporting this. We looked into it and it’s a regression introduced in .71 inside React Native. We’ll be pushing a fix out (cc @blakef is working on it) and we’ll pick it for RC4 (cc @kelset for visibility).
I believe this is expected as these are independently defined messages for distinct WebSocket events (defined here and here). However, perhaps we can address this papercut by adding the similar help output on restarting Metro for the
close
event (the one in your iOS Simulator screenshot).