Node JS and Webpack Unexpected token <

Your server:

var Server = http.createServer(function(request, response) {
  var filename = path.join(__dirname, 'index.html');

… is configured to ignore everything in the request and always return the contents of index.html.

So when the browser requests /assets/bundle.js it is given index.html (and errors because that isn't JavaScript).

You need to pay attention to the path and serve up appropriate content, with the appropriate content type.

This would probably be best done by finding a static file serving module (Google turns up node-static) for Node (or replacing Node with something like Lighttpd or Apache HTTPD).

If you want to serve up dynamic content as well as static content, then Express is a popular choice (and has support for static files).


No matter what is requested by the browser, your server will always return the same exact file: index.html.

The error you are seeing is because your HTML file has a reference to bundle.js, which, when requested, is returned with the contents of index.html.

You should use a web framework so that you don't have to worry about these things. E.g. Express.