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

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();


Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jefelewis
Solution 2 110PercentJoe
Solution 3 balloon
Solution 4 Adrian Buciuman