metro icon indicating copy to clipboard operation
metro copied to clipboard

Symbolicate fails when using metro CLI directly

Open rockwotj opened this issue 3 years ago • 1 comments

Do you want to request a feature or report a bug?

Bug 🐛

What is the current behavior?

When running the metro CLI directly there are many errors like:

SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at node_modules/metro/src/Server.js:1025:28
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (node_modules/metro/src/Server.js:99:24)
    at _next (node_modules/metro/src/Server.js:119:9)

Some debugging shows that rawBody is undefined and it's trying to be json parsed.

There is a comment in the code about not understanding where rawBody comes from:

https://github.com/facebook/metro/blob/af23a1b27bcaaff2e43cb795744b003e145e78dd/packages/metro/src/Server.js#L1028-L1029 I believe this isn't a bigger issue because the react native CLI provides this middleware automatically:

https://github.com/react-native-community/cli/blob/760708fc3216aee565f59877a103a7e35df2d77d/packages/cli-server-api/src/index.ts#L60

Should that middleware be moved down a layer or the code rewritten to not use this field?

rockwotj avatar Apr 12 '21 14:04 rockwotj

I had a similar issue in my codebase. It is a little bit strange, bc this problem is not reproducible on the fresh react native app. In my codebase I had a below error: Unable to symbolicate stack trace: JSON Parse error: Unexpected EOF

I was comparing both JSON (from the fresh app and from my app) and they are identical. so I don't know, where the issue can be.

troZee avatar Jun 01 '21 12:06 troZee

Just bumped into this issue today when trying to run metro manually from JS.

As @rockwotj pointed out, seems that metro assumes that it will always be used with a middleware that's added from the react-native cli which is not always the case.

sbalay avatar Jan 02 '23 15:01 sbalay