A
A
Azat S.2016-01-29 00:51:04
JavaScript
Azat S., 2016-01-29 00:51:04

Error in react "Hello, world!", what could be wrong?

I'm trying to run the simplest Hello World React, but it doesn't work, instead Webpack gives an error. Please tell me what am I doing wrong?
package.json:

{
  "name": "reactcase",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "dependencies": {
    "react": "^0.14.7",
    "react-dom": "^0.14.7"
  },
  "devDependencies": {
    "babel-core": "^6.4.5",
    "babel-loader": "^6.2.1",
    "babel-preset-es2015": "^6.3.13",
    "babel-preset-react": "^6.3.13",
    "webpack": "^1.12.12"
  }
}

webpack.config.js:
module.exports = {
  entry: "./app/components/main.js",
  output: {
    filename: "public/bundle.js"
  },
  module: {
    loaders: [
      {
        test: /\.jsx$/,
        exclude: /(node_modules)/,
        loader: 'babel',
        query: {
          presets: ['react', 'es2015']
        }
      }
    ]
  }

app/components/main.js:
var React = require('react');
var ReactDOM = require('react-dom');

var Main = React.createClass({
  render: function() {
    return (
      <div>
        Hello, world!
      </div>
    )
  }
});

ReactDOM.render(<Main />, document.getElementById('app'));

In general, this whole thing produces a simple error:
[email protected]:~/git/reactcase$ webpack -w
Hash: efea76b1048c3a97b963
Version: webpack 1.12.12
Time: 41ms
    + 1 hidden modules

ERROR in ./app/components/main.js
Module parse failed: /home/azat/git/reactcase/app/components/main.js Line 7: Unexpected token <
You may need an appropriate loader to handle this file type.
|   render: function() {
|     return (
|       <div>
|         Hello, world!
|       </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zakhar Orlov, 2016-01-29
@azat-io

test: /\.jsx$/Webpack only looks at .jsx files and applies a loader to them
test: /\.jsx?$/so webpack will take both .js and .jsx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question