When I boot up my application on android and then click on the login button, I get the following error:
2019-08-15 10:50:19.242 10338-12350/com.nfibengage W/ReactNativeJS: Require cycle: src/services/Requester.js -> src/utils/appcenterLogger.js -> src/services/Requester.js
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
2019-08-15 10:50:22.534 10338-12350/com.nfibengage E/ReactNativeJS: TypeError: null is not an object (evaluating 'AppCenterReactNativeAnalytics.trackEvent')
This error is located at:
in NavigationContainer (at RootNavigation.js:216)
in RootNavigation (created by Connect(RootNavigation))
in Connect(RootNavigation) (at App.js:247)
in RCTView (at View.js:35)
in View (at App.js:245)
in Provider (at App.js:244)
in NFIBEngage (at renderApplication.js:40)
in RCTView (at View.js:35)
in View (at AppContainer.js:98)
in RCTView (at View.js:35)
in View (at AppContainer.js:115)
in AppContainer (at renderApplication.js:39)
2019-08-15 10:50:23.185 10338-11447/com.nfibengage W/unknown:ReactNative: Calling JS function after bridge has been destroyed: RCTDeviceEventEmitter.emit(["Sentry/eventSentSuccessfully",{"tags":{},"extra":{"session:duration":3799},"dist":"1","release":"com.nfibengage-1.0","message":"TypeError: null is not an object (evaluating 'AppCenterReactNativeAnalytics.trackEvent')\n\nThis error is located at:\n in NavigationContainer (at RootNavigation.js:216)\n in RootNavigation (created by Connect(RootNavigation))\n in Connect(RootNavigation) (at App.js:247)\n in RCTView (at View.js:35)\n in View (at App.js:245)\n in Provider (at App.js:244)\n in NFIBEngage (at renderApplication.js:40)\n in RCTView (at View.js:35)\n in View (at AppContainer.js:98)\n in RCTView (at View.js:35)\n in View (at AppContainer.js:115)\n in AppContainer (at renderApplication.js:39)","level":"fatal","event_id":"3dfe7c1e-820c-4eab-9f90-38a7f5ce570b"}])
This only happens in android.
I refactored the two files requiring each other by dropping the logic of src/services/Requester.js into appcenterLogger.js and adjusting relative paths and bringing over the imports as well.
Unfortunately, the error persists. I have been able to identify the following code snippet from RootNavigation.js as a problem:
_screenTracking = (prevState, currentState) => {
const currentScreen = this._getCurrentRouteName(currentState);
const prevScreen = this._getCurrentRouteName(prevState);
// if (prevScreen !== currentScreen) {
// appcenter.trackNavigation(prevScreen, currentScreen);
// }
};
render() {
if (
this.props.user &&
this.props.user.authStatus === AUTH_STATUS.LOGGED_IN
) {
return (
<DrawerStack
ref={nav => {
this.navigator = nav;
}}
onNavigationStateChange={this._screenTracking}
/>
);
}
return (
<AuthStack
authStatus={this.props.user.authStatus}
// onNavigationStateChange={this._screenTracking}
ref={nav => {
this.navigator = nav;
}}
/>
);
}
}
const mapStateToProps = ({ auth, registrations, navigation }) => {
const { user } = auth;
return {
user,
resetPasswordDeepLinkKey: registrations.resetPasswordData.resetKey,
...navigation
};
};
export default connect(
mapStateToProps,
{
resetState,
setSelectedEvent,
setSelectedSurvey,
setSelectedArticle,
setSelectedAlert
}
)(RootNavigation);
At this point, I am unclear as to why I am having this problem with RootNavigation.js, since everywhere I have inspected the Analytics module is returning an object:
Object
PropertyConfigurator: ƒ _class(transmissionTarget)
TransmissionTarget: ƒ _class2(targetToken)
bindingType: "MSAnalytics"
getTransmissionTarget: ƒ getTransmissionTarget(targetToken)
isEnabled: ƒ isEnabled()
setEnabled: ƒ setEnabled(enabled)
trackEvent: ƒ trackEvent(eventName, properties)
arguments: null
caller: null
length: 2
name: "trackEvent"
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: Analytics.js:8
[[Scopes]]: Scopes[2]
__proto__: Object
It was suggested that trackEvent requires passing a dictionary but this may be interpreted as an array. So I attempted to change this in appcenterLogger.js:
export function trackNavigation(from, to) {
Analytics.trackEvent("AppNavigation", { from, to });
console.log(Analytics);
}
to:
export function trackNavigation(from, to) {
Analytics.trackEvent("AppNavigation", { from: from, to: to });
console.log(Analytics);
}
or
export function trackNavigation(from, to) { Analytics.trackEvent("AppNavigation"); console.log(Analytics); }
but the error persists. I am unclear as to how a module that exists as an object everywhere I inspect it in the project ends up returning null is not an object.
from TypError: null is not an object (evaluating 'AppCenterReactNativeAnalytics.trackEvent')
try this...JavaScript Interview Questions
ReplyDelete