Search code examples
reactjsreact-nativewebpackbabeljsreact-native-web

Unable to run webpack-dev-server on react-native-web. ERROR: You may need an appropriate loader to handle this file type


I am trying to dive into React ecosystem and having issues with using react-native-web with my React Native Application. I have hosted the application on https://github.com/thedarklord1/testNativeWithWeb. I have used Redux Store and React Native to build a very simple POC to build a calculator. The Android and the iOS versions are executing as expected. The issue that I am facing is that, while trying to run webpack-dev-server, to use react-native-web for web, it is failing with the error

ERROR in ./src/App.js
Module parse failed: /Users/abhishekkumar/Desktop/Credifiable/front_end/testNativeWithWeb/src/App.js Unexpected token (9:6)
You may need an appropriate loader to handle this file type.
|   render() {

|     return (
|       <Provider store={store}>
|         <AppContainer/>
|       </Provider>
 @ ./index.web.js 1:0-28
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./index.web.js

I am fairly new to the React and WebPack ecosystem and any help or pointer is appreciated. TIA.

EDIT: I am using the command webpack-dev-server -d --config web/webpack.config.js --inline --hot --colors to run the server.


Solution

  • You need to transpile to es2015 since most of the browsers do not natively understand modern JS.

    loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015', 'stage-0', 'react']
                }
            }
        ]
    

    Add a loader to your webpack config. It should work then.