I'm walking through a react tutorial at http://andrewhfarmer.com/build-your-own-starter/#0-intro and the Counter component won't show up on the page. The html comes out like this:
<html>
<head>
<script src="/bundle.js" ></script>
</head>
<body>
<div id="mount"></div>
</body>
</html>
main.js
console.log('Hello World!');
import React from 'react';
import ReactDOM from 'react-dom';
import Counter from './Counter';
ReactDOM.render(
React.createElement(Counter),
document.getElementById('mount')
);
Counter.js
import React from 'react';
class Counter extends React.Component {
constructor() {
super();
this.state = {
count: 0,
};
}
render() {
return (
<button
onClick={() => {
this.setState({ count: this.state.count + 1 });
}}
>
Count: {this.state.count}
</button>
);
}
}
export default Counter;
webpack.config.js
var path = require('path');
var config = {
context: path.join(__dirname, 'src'),
entry: [
'./main.js',
],
output: {
path: path.join(__dirname, 'www'),
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader'],
},
],
},
resolveLoader: {
root: [
path.join(__dirname, 'node_modules'),
],
},
resolve: {
root: [
path.join(__dirname, 'node_modules'),
],
},
};
module.exports = config;
We run server:
cchilders@cchilders-Latitude-E7240:~/CodeTutorials/build-react-starter$ node server.js
in the component
in the tester
in the component
in the tester
Example app listening at http://:::3000
Hash: d51a7c75081bea020fb1
Version: webpack 1.14.0
Time: 1297ms
Asset Size Chunks Chunk Names
bundle.js 744 kB 0 [emitted] main
chunk {0} bundle.js (main) 707 kB [rendered]
[0] multi main 28 bytes {0} [built]
[179] ./src/Counter.js 2.63 kB {0} [built]
webpack: bundle is now VALID.
Refreshing page shows nothing in terminal, but developer tools console shows the Hello World! on each refresh
It seems template isn't being rendered, but the last time my friend did the tutorial it worked as is (the public aspect in the middleware might have served it)
Why is this server not serving files from /?
The code is at https://bitbucket.org/servandoavila1/codetutorials
Thank you
Hello world!when you refresh page