Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
like image 438
jefelewis Avatar asked Aug 10 '20 04:08

jefelewis


3 Answers

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

like image 57
jefelewis Avatar answered Nov 13 '22 23:11

jefelewis


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.

like image 32
110PercentJoe Avatar answered Nov 13 '22 22:11

110PercentJoe


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

like image 1
Adrian Buciuman Avatar answered Nov 13 '22 21:11

Adrian Buciuman