Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot GET / error running hello world in webpack

Tags:

Full Github project: https://github.com/pbrianmackey/uiexperiment

I run

webpack-dev-server --content-base deployment/

Then go to http://localhost:8080/, Error

Cannot GET /

I think the problem is a misconfiguration of webpack. I checked by webpack.config.js file and don't see a problem. How can I fix this so I get my hello world example?

It could be a routing problem too. I think I can use this website without react-router, but I could be wrong. There are no errors in webpacks output on the console.

index.js

import "babel-polyfill";//for flipping IE import $ from 'jquery'; import jQuery from 'jquery'; var App = require('./app'); var React = require('react'); var ReactDOM = require('react-dom')  var Hello = React.createClass({   render: function() {     return <div>Hello {this.props.name}</div>;   } });  ReactDOM.render(   <Hello name="World" />,   document.getElementById('container') ); 
like image 515
P.Brian.Mackey Avatar asked Jun 21 '16 21:06

P.Brian.Mackey


People also ask

What is the default port where Webpack?

What is the default port where webpack server runs? 8080 ? The default port to run web-pack-server is 8080.

How do I start Webpack in watch mode?

You can also enable watch mode from your Webpack config file: module. exports = { mode: 'development', watch: true, // Enable watch mode entry: { app: `${__dirname}/app.

What does bin Webpack dev server do?

webpack-dev-server is Webpack's officially supported CLI-based tool for starting a static server for your assets. While you don't need any CLI tools to use Webpack, webpack-dev-server gives you a single command that starts a static server with built-in live reload.


2 Answers

Turns out I had index.html in the wrong place. From the webpack docs:

To load your bundled files, you will need to create an index.html file in the build folder from which static files are served (--content-base option).

I made a copy of index.html in a new folder I called deployment to match what I specified in the output.path

like image 193
P.Brian.Mackey Avatar answered Oct 07 '22 09:10

P.Brian.Mackey


In the webpack.config.js put this :

devServer: {   historyApiFallback: true, } 
like image 33
Manuel Carmona Avatar answered Oct 07 '22 10:10

Manuel Carmona