7

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.

5
  • share your webpack and package.json Aug 10, 2017 at 12:02
  • Hey Vikram, webpack config and package.json, both I have put up at github.com/thedarklord1/testNativeWithWeb
    – Abhishek
    Aug 16, 2017 at 5:11
  • try to install npm install babel-preset-es2015 and then configure babel-loader as { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ['es2015'] } } Aug 16, 2017 at 6:02
  • seems like something is wrong with babel-loader configuration.Also try changing test: to test: /\.jsx?$/, in babelloaderconfiguration Aug 16, 2017 at 6:10
  • Will definitely give it a shot, and get back with findings. Thanks!
    – Abhishek
    Aug 16, 2017 at 6:32

2 Answers 2

4
+25

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.

1
  • This, plus don't forget to actually install the loaders as npm packages.
    – Mentor
    Aug 21, 2017 at 10:35
3

In your package.json replace the script tag with

  "scripts": {
    "start": "webpack-dev-server --hot"
  },

and install "webpack-dev-server --hot" using npm install webpack-dev-server --hot

And run your app using

npm start

Also you need to enclose your code in tag inside return as

 render() {

     return (
<div>
       <Provider store={store}>
         <AppContainer/>
       </Provider>
</div>

and make sure you have installed all the babel dependencies to compile your code

1
  • Hey Vikram, This is not the answer that I am looking for. Your solution does not solve my problem. Thanks!
    – Abhishek
    Aug 16, 2017 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.