Please provide the following:
- SDK Version: 41
- Platforms(Android/iOS/web/all): iOS
- Add the appropriate “Tag” based on what Expo library you have a question on.
- Workflow: Bare
After upgrading to Expo 41 I’m getting the following error as soon as my app loads:
TypeError: undefined is not an object (evaluating '_ExpoKeepAwake.default.activate')
.
Full error with stack trace:
ERROR TypeError: undefined is not an object (evaluating '_ExpoKeepAwake.default.activate')
This error is located at:
in ExpoRoot (at renderApplication.js:47)
in RCTView (at View.js:34)
in View (at AppContainer.js:107)
in RCTView (at View.js:34)
in View (at AppContainer.js:134)
in AppContainer (at renderApplication.js:40)
This error is not coming from my code. I’m not directly using expo-keep-awake
anywhere in my code. It’s not even listed in my package.json
file. I was able to make the error go away by making the following manual edits to the expo package in node_modules/
directory:
// node_modules/expo/build/launch/withExpoRoot.js
import * as ErrorRecovery from 'expo-error-recovery';
import * as React from 'react';
// This hook can be optionally imported because __DEV__ never changes during runtime.
// Using __DEV__ like this enables tree shaking to remove the hook in production.
// Comment out all of this code
//let useDevKeepAwake = () => { };
//if (__DEV__) {
// try {
// // Optionally import expo-keep-awake
// const { useKeepAwake } = require('expo-keep-awake');
// useDevKeepAwake = useKeepAwake;
// }
// catch { }
//}
export default function withExpoRoot(AppRootComponent) {
return function ExpoRoot(props) {
// Comment out this line too
// useDevKeepAwake();
const combinedProps = {
...props,
exp: { ...props.exp, errorRecovery: ErrorRecovery.recoveredProps },
};
return React.createElement(AppRootComponent, Object.assign({}, combinedProps));
};
}
//# sourceMappingURL=withExpoRoot.js.map
Looking at the stack trace, it looks like this is where the error is occurring:
// node_modules/expo-keep-awake/src/index.ts
export function activateKeepAwake(tag: string = ExpoKeepAwakeTag): void {
// ExpoKeepAwake is undefined here
if (ExpoKeepAwake.activate) ExpoKeepAwake.activate(tag);
}
I can also make this error go away by running the app in Release mode rather than Debug mode, because that sets __DEV__
equal to false, but then I lose hot-reloading.