Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flipper 0.126 crashing metro #3189

Closed
artstylee opened this issue Dec 18, 2021 · 12 comments
Closed

Flipper 0.126 crashing metro #3189

artstylee opened this issue Dec 18, 2021 · 12 comments

Comments

@artstylee
Copy link

artstylee commented Dec 18, 2021

馃悰 Bug Report

after installing flipper 0.126 my metro crashing every time with an error

D:\docs\proj\react-express-jwt-full\motoNative\node_modules\metro-he
rmes-compiler\src\emhermesc.js:77
          throw ex;
          ^

TypeError: Cannot read properties of undefined (reading 'startsWith'
)

Environment

WIN 10

@mweststrate
Copy link
Contributor

This should be fixable by changing node_modules/@react-native-community/cli-server-api/build/websocket/eventSocketServer.js line 131 from return origin.startsWith('http://localhost:') || origin.startsWith('file:'); to return !origin || origin.startsWith('http://localhost:') || origin.startsWith('file:');.

I'll try to submit a PR for that when back from PTO, or feel free to submit a PR already at https://github.com/react-native-community/cli/blob/master/packages/cli-server-api/src/websocket/eventsSocketServer.ts#L129. You can solve the issue locally by using patch-package

@ghost
Copy link

ghost commented Dec 20, 2021

Faced with this issue too, downgrading Flipper to 0.125 will fix it

@artstylee
Copy link
Author

ye i downgrade too

@realtril
Copy link

realtril commented Dec 20, 2021

@davydspotnana @artstylee how did you downgrade a flipper? I mean, how can I downgrade the desktop app?

@sytolk
Copy link

sytolk commented Dec 20, 2021

the same issue on Mac

info Opening flipper://null/Hermesdebuggerrn?device=React%20Native...
/Users/sytolk/IdeaProjects/drivefuel-app/DriveApp/node_modules/metro-hermes-compiler/src/emhermesc.js:77
          throw ex;
          ^

TypeError: Cannot read property 'startsWith' of undefined
    at Object.verifyClient (/Users/sytolk/IdeaProjects/drivefuel-app/DriveApp/node_modules/@react-native-community/cli-server-api/build/websocket/eventsSocketServer.js:131:21)
    at WebSocketServer.handleHybiUpgrade (/Users/sytolk/IdeaProjects/drivefuel-app/DriveApp/node_modules/ws/lib/WebSocketServer.js:331:28)
    at WebSocketServer.handleUpgrade (/Users/sytolk/IdeaProjects/drivefuel-app/DriveApp/node_modules/ws/lib/WebSocketServer.js:173:26)
    at Server.WebSocketServer._onServerUpgrade (/Users/sytolk/IdeaProjects/drivefuel-app/DriveApp/node_modules/ws/lib/WebSocketServer.js:89:12)
    at Server.emit (events.js:412:35)
    at onParserExecuteCommon (_http_server.js:700:14)
    at onParserExecute (_http_server.js:613:3)
Process terminated. Press <enter> to close the window

downgrade here: https://github.com/facebook/flipper/releases

@realtril
Copy link

@sytolk thank you!

@renchap
Copy link

renchap commented Dec 20, 2021

@mweststrate I have been able to test your fix and it works.

I can make a PR, but I am not sure this is the best issue as this check is here for security reasons, and allowing empty origins could be an issue.

@nikoden-io
Copy link

nikoden-io commented Dec 20, 2021

Thanks @mweststrate ! Your solution works for me
EDIT: the fix works but need repeated modification, don't have find yet what update this file on my project

@amirping
Copy link

+1

mweststrate added a commit to mweststrate/cli that referenced this issue Dec 22, 2021
Fixes per work around: facebook/flipper#3189 (comment). The same fix has been applied to FB infra, and the next release will temporarily set an `origin` header as work around for existing RN versions. 

Fixes:
* facebook/flipper#2870
* facebook/flipper#3189

The essence of the fix is that we shouldn't check the `origin` header if it is not present. That might sound unsafe, but it actually is just a check to protect from malicious websites, and browsers ensure the origin header is set for cross site requests. For websocket connections created outside a browser context, the creator has full control over the origin header anyway, so checking it would not add any safety.
facebook-github-bot pushed a commit that referenced this issue Dec 22, 2021
Summary:
Changelog: Work-around for missing `origin` header problem #3189; causing Metro to crash when Flipper tries to connect

Will follow up with separate fix in React Native itself as well

Reviewed By: nikoant

Differential Revision: D33276414

fbshipit-source-id: 34d1510262ac24172ac1c6660799bb755b0f1f11
@ghost
Copy link

ghost commented Dec 22, 2021

Happens on MacOS with Apple Silicon as well.

@mweststrate
Copy link
Contributor

Should be fixed in Flipper 0.127 which will ship later today, and/or in the next version of RN

thymikee pushed a commit to react-native-community/cli that referenced this issue Dec 22, 2021
* Fix metro crash when Flipper connects

Fixes per work around: facebook/flipper#3189 (comment). The same fix has been applied to FB infra, and the next release will temporarily set an `origin` header as work around for existing RN versions. 

Fixes:
* facebook/flipper#2870
* facebook/flipper#3189

The essence of the fix is that we shouldn't check the `origin` header if it is not present. That might sound unsafe, but it actually is just a check to protect from malicious websites, and browsers ensure the origin header is set for cross site requests. For websocket connections created outside a browser context, the creator has full control over the origin header anyway, so checking it would not add any safety.

* Fix lint error
@fergalmoran
Copy link

I'm not sure this is a duplicate of #1523 ? I downgraded to 0.125.0 then upgraded to 0.127.0 but none of them fixed my issue.
Flipper connects to my device but the hermes plugin is disabled.

Device plugin 'Hermes Debugger (RN)' is not supported by the selected device 'Pixel_5_API_30' (Android).```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants