Answer the question
In order to leave comments, you need to log in
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"
}
}
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']
}
}
]
}
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'));
[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
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 questionAsk a Question
731 491 924 answers to any question