Talha Arshad
Talha Arshad

Reputation: 143

Error running react native project using async storage on web platform

I am trying to run a React Native test app on a web platform.
I have installed @react-native-community/async-storage dependency.
It generates the following error:

ERROR in ./node_modules/@react-native-community/async-storage/lib/AsyncStorage.js 40:5 Module parse failed: Unexpected token (40:5) You may need an appropriate loader to handle this file type. | } | type ReadOnlyArrayString = $ReadOnlyArray; | | type MultiGetCallbackFunction = ( @ ./node_modules/@react-native-community/async-storage/lib/index.js 5:0-42 7:15-27 @ ./src/app.js @ ./index.web.js @ multi (webpack)-dev-server/client?http://0.0.0.0:8080 (webpack)/hot/dev-server.js ./index.web.js

ERROR in ./node_modules/@react-native-community/async-storage/lib/hooks.js 7:5 Module parse failed: Unexpected token (7:5) You may need an appropriate loader to handle this file type. | import AsyncStorage from './AsyncStorage'; | type AsyncStorageHook = { | getItem: ( | callback?: ?(error: ?Error, result: string | null) => void, @ ./node_modules/@react-native-community/async-storage/lib/index.js 8:0-40 8:0-40 @ ./src/app.js @ ./index.web.js @ multi (webpack)-dev-server/client?http://0.0.0.0:8080 (webpack)/hot/dev-server.js ./index.web.js

Note: Code is running on Android, but it is not running on Web.

Upvotes: 1

Views: 677

Answers (1)

Mohit
Mohit

Reputation: 49

resolve: {
    alias: {
        '@react-native-community/async-storage': 'react-native-web'
    }
}

create a resolve alias in your webpack.config.json.

This might help you

Upvotes: 2

Related Questions