1

I'm trying to a basic React setup with Webpack, but currently getting this console error on the html I'm trying to render.

Not sure why, any ideas?

Module build failed: SyntaxError:

Javascript

import React from "react";
import { render } from "react-dom";

class App extends React.Component {
    render() {
        return (
            <p>h</p>
        )
    }
}

render(<App/>, document.getElementById('main'));

Webpack Config

const webpack = require('webpack');
const nodeEnv = process.env.NODE_ENV || "production";

module.exports = {
    devtool: "source-map",
    entry: {
        filename: "./index.js"
    },
    output: {
        filename: "build/bundle.js"
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['es2015-native-modules']
                }
            }
        ]
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            compress: { warnings: false },
            output: { comments: false },
            sourcemap: true
        }),
        new webpack.DefinePlugin({
            'process.env': { NODE_ENV: JSON.stringify(nodeEnv
            )}
        })
    ]
}

Package.JSON

{
  "name": "joe-react",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack --progress --watch"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  },
  "devDependencies": {
    "babel-core": "^6.24.0",
    "babel-loader": "^6.4.1",
    "babel-preset-es2015-native-modules": "^6.9.4",
    "webpack": "^2.3.2"
  }
}

1 Answer 1

1

You need babel react preset, and I see you use strange preset now, use es2015 instead

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this. For anyone wondering I uninstalled 'babel-preset-es2015-native-modules' and installed 'babel-preset-es2015' instead and changed my webpack.config.js to 'es2015' instead of 'es2015-native-modules'. I also installed 'babel-preset-react' and added that in my presets in webpack.config.js.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.