catalinmiron / react-native-plaid-link

React Native Plaid authenticator
124 stars 55 forks source link

SyntaxError: JSON Parse error: Unexpected identifier "setImmediate$0" #56

Open cloudpresser opened 3 years ago

cloudpresser commented 3 years ago

When the WebView loads, it throws the error:

SyntaxError: JSON Parse error: Unexpected identifier "setImmediate$0"
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:9:32 in ErrorUtils.setGlobalHandler$argument_0
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

It seems like the error is cause because the plaid link page is running window.postMessage with a string containing setImmediate$0 which is then passed to JSON.parse(e.nativeEvent.data), and since it is not valid JSON, it throws the error.

cloudpresser commented 3 years ago

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-plaid-link/index.js b/node_modules/react-native-plaid-link/index.js
index 4a4013e..90d423c 100644
--- a/node_modules/react-native-plaid-link/index.js
+++ b/node_modules/react-native-plaid-link/index.js
@@ -82,8 +82,11 @@ class PlaidAuthenticator extends Component {
         }
       }
     */
-
-    this.props.onMessage(JSON.parse(e.nativeEvent.data));
+    try {
+        this.props.onMessage(JSON.parse(e.nativeEvent.data));
+    } catch (err) {
+      this.props.onMessage(e.nativeEvent.data)
+    }
   };
 }