D
D
dhat2016-09-12 16:06:43
React
dhat, 2016-09-12 16:06:43

Webpack throws error, doesn't understand React syntax?

Sel dealt with webpack. I watch the introductory video and repeat after it. Elementary project, but webpack throws an error:

ERROR in ./index.js
Module build failed: SyntaxError: Unexpected token (5:15)

  3 | const App = React.createClass({
  4 |     render() {
> 5 |         return <h1>h1 lol</h1>
    |                ^
  6 |     }
  7 | })
  8 |

index.html:
<section id="target">not rendered yet</section>
index.js:
const React = require('react')

const App = React.createClass({
    render() {
        return <h1>h1 lol</h1>
    }
})

React.render(<App/>, window.document.getElementById('target'))

webpack.config.js:
module.exports = {
    entry: "./index.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { loader: "babel" }
        ]
    }
}

Where is the mistake? I just need to render a phrase to check that everything works.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dhat, 2016-09-12
@dhat

Understood. Need ReactDOM.render() and react-dom module

R
Rikcon, 2016-09-12
@Rikcon

Guess what you forgot.
https://stackoverflow.com/questions/33460420/babel...
babel didn't enter your jsx because you didn't tell him how to cook it, read the answer here and you'll be happy.

M
Mikhail Osher, 2016-09-12
@miraage

babel-preset-react

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question