I followed the basic webpack guide and I have a server up and running. When I change files, it will be updated when saved, everything is fine. However, I introduced React back then, and it all went wrong.
Firstly, I get this error in the browser:
Unexpected token < You may need an appropriate loader to handle this file type.
This points to line 4 in the entry.js file:
var CommentBox = React.createClass({ render: function() { return ( <div className="commentBox"> Hello, world! I am a CommentBox. </div> ); } }); ReactDOM.render( <CommentBox />, document.getElementById('content') );
This is index.html
<html> <head> <meta charset="utf-8"> </head> <body> <div id ="content"></div> <script type="text/javascript" src="bundle.js" charset="utf-8"></script> </body> </html>
webpack.config.js:
module.exports = { entry: "./entry.js", output: { path: __dirname, filename: "bundle.js" }, module: { loaders: [ { test: /\.jsx?$/, loader: 'jsx-loader?insertPragma=React.DOM&harmony' } ] }, externals: { 'react': 'React' }, resolve: { extensions: ['', '.js', '.jsx'] } };
If I entry.js file to just contain:
document.write(require("./content.js"));
It creates what I have in the content.js file:
module.exports = "this is working";
So this has something to do with the / jsx reaction, etc. Has anyone got any solutions? I have seen other people on the Internet with this problem, but the solutions provided have not yet worked.