React Native TypeScript Error: Module '"react-native"' has no exported member 'Appearance'

Viewed 9444

I've recently implemented dark mode into my app, but having an issue with an error when building the npm package with npm build. The code works, but is there a way or a reason to remove this error?

React Native Docs: Appearance

Error

src/ContactActionSheet.tsx:3:10 - error TS2305: Module '"react-native"' has no exported member 'Appearance'.

3 import { Appearance, Dimensions, StyleSheet, Text, View, Linking, TouchableOpacity } from 'react-native';

JSX

// Imports: Dependencies
import { Appearance, Dimensions, StyleSheet, Text, View, Linking, TouchableOpacity } from 'react-native';

// Dark Mode
const colorScheme = Appearance.getColorScheme();
4 Answers

The issue was with the npm package @types/react-native needing to be updated.

Thanks for following up with a response. After checking what version I was on, I discovered I didn't even have the @types/react-native module added. Once I added that, my issue was resolved. Strange how if you start a project with TypeScript, it is not guaranteed to even have that dependency.

I tried npm install --save @types/react-native but it didn't work. I had to add @latest at the end on order to get a proper update of the version. try this command npm install --save @types/react-native@latest

If you are using Vscode and find this error message linting, it is because you didn't add @types/... including @types/react-native

Related