Can't set up webpack-dev-server to start React appHow to auto-reload files in Node.js?Make webpack-dev-server to do hot reloading AND eliminate EMPTY response error in ReactHow to allow for webpack-dev-server to allow entry points from react-routerManaging jQuery plugin dependency in webpackDo I need webpack-dev-server if I am using a node server like expressbabel-loader jsx SyntaxError: Unexpected tokenI am getting an “Invalid Host header” message, when running my React app in a Webpack dev server on Cloud9.iowebpack-dev-server: Cannot get /webpack-dev-middleware with create-react-appreact-hot-loader and webpack not workingreact-hot-loader and webpack-dev-server don't reload changesERROR in multi ../node_modules/webpack-dev-server/client?http://localhost:8080 ./app/index.js
How frequently do Russian people still refer to others by their patronymic (отчество)?
Will Jimmy fall off his platform?
Do intermediate subdomains need to exist?
What instances can be solved today by modern solvers (pure LP)?
Is it possible to spoof an IP address to an exact number?
Is it bad to suddenly introduce another element to your fantasy world a good ways into the story?
Is there a name for non-Benders in the Avatar universe?
Is it acceptable that I plot a time-series figure with years increasing from right to left?
What is the shape of the upper boundary of water hitting a screen?
Do Goblin tokens count as Goblins?
Is it possible that Curiosity measured its own methane or failed doing the spectrometry?
Find max number you can create from an array of numbers
Bypass with wrong cvv of debit card and getting OTP
Motorcyle Chain needs to be cleaned every time you lube it?
How serious is plagiarism in a master’s thesis?
Can a USB hub be used to access a drive from 2 devices?
Why do Klingons use cloaking devices?
Speeding up thousands of string parses
What's the difference between 反面 and 一方?
Do I need to be legally qualified to install a Hive smart thermostat?
How do I iterate equal values with the standard library?
Taking advantage when the HR forgets to communicate the rules
How can a ban from entering the US be lifted?
Should I warn my boss I might take sick leave?
Can't set up webpack-dev-server to start React app
How to auto-reload files in Node.js?Make webpack-dev-server to do hot reloading AND eliminate EMPTY response error in ReactHow to allow for webpack-dev-server to allow entry points from react-routerManaging jQuery plugin dependency in webpackDo I need webpack-dev-server if I am using a node server like expressbabel-loader jsx SyntaxError: Unexpected tokenI am getting an “Invalid Host header” message, when running my React app in a Webpack dev server on Cloud9.iowebpack-dev-server: Cannot get /webpack-dev-middleware with create-react-appreact-hot-loader and webpack not workingreact-hot-loader and webpack-dev-server don't reload changesERROR in multi ../node_modules/webpack-dev-server/client?http://localhost:8080 ./app/index.js
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I was using a simple script before to start a React app but I need to reload, rebuild, and restart everything manually this way which is tedious. Now I am trying to set up webpack-dev-server to do that for me. Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app. Previously I used the following script to start the app (it is working good):
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('nodetest1:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val)
var port = parseInt(val, 10);
if (isNaN(port))
// named pipe
return val;
if (port >= 0)
// port number
return port;
return false;
/**
* Event listener for HTTP server "error" event.
*/
function onError(error)
if (error.syscall !== 'listen')
throw error;
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code)
case 'EACCES':
console.error(bind + ' requires elevated privileges'); process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
The webpack.config.js looks the following way:
var path = require('path');
module.exports =
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
output:
filename: 'bundle.js',
path: path.resolve(__dirname, './public')
,
devtool: "#eval-source-map",
module:
rules: [
test: /.jsx?$/,
exclude: /node_modules/,
use:
loader: 'babel-loader?cacheDirectory=true',
,
test: /.css$/,
loader: "style-loader!css-loader"
,
gif]
,
node:
fs: 'empty'
,
resolve:
extensions: ['.js', '.jsx']
,
externals:
fs: '',
tls: '',
net: '',
dns: '',
readline: ''
;
Upon starting the app with the ./node_modules/.bin/webpack-dev-server --inline --hot I see the following output:

Any suggestions would be greatly appreciated.
Update
I changed name of the file which is an entry point from app.html to index.html in the public folder and also changed the command to start the app to ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot and the app started but the requests to the node server result in 404 errors, the server is not processing requests somehow. I guess that can be because app.js script was not run and so all the middleware was not set up, but I am not sure how to pre-run it or package into the bundle.js. I have two layers though: app.js runs and presents the login page and then redirects to the actual app if the login is successful (it is not needed for the development of course).
Update
I tried using nodemon: How to auto-reload files in Node.js?
By doing the following: nodemon ./bin/www where www is the server script. It is not watching for my changes at all. When I change some of .jsx files, no reloading happens.
Update
I tried to change the entry point in webpack.config.js from:
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
to:
entry:
app: ['babel-polyfill', './app.js']
//vendor: ["react","react-dom"]
,
But in this case when building the app it is giving me the error:

Following the advice here: https://github.com/webpack/webpack/issues/2142
I set target: node in the webpack.config.js. It started giving me another error:

I found the following solution: https://github.com/babel/babel/issues/5268
But after running npm install --save babel-standalone the error remained.
Update
I was able to fix the error by adding .json to the extensions: https://github.com/discordjs/discord.js/issues/2656
Now webpack compiled the project successfully and without any errors, however, when I started it with ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot in the browsers' console I see the error: Uncaught ReferenceError: require is not defined and nothing loads.
Update
I was trying to follow: https://hackernoon.com/full-stack-web-application-using-react-node-js-express-and-webpack-97dbd5b9d708
And it is running fine but when I change the React files, the app is not reloaded. Also babel set ups there messed up my project completely, so I can not build the project now.
reactjs webpack
add a comment |
I was using a simple script before to start a React app but I need to reload, rebuild, and restart everything manually this way which is tedious. Now I am trying to set up webpack-dev-server to do that for me. Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app. Previously I used the following script to start the app (it is working good):
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('nodetest1:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val)
var port = parseInt(val, 10);
if (isNaN(port))
// named pipe
return val;
if (port >= 0)
// port number
return port;
return false;
/**
* Event listener for HTTP server "error" event.
*/
function onError(error)
if (error.syscall !== 'listen')
throw error;
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code)
case 'EACCES':
console.error(bind + ' requires elevated privileges'); process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
The webpack.config.js looks the following way:
var path = require('path');
module.exports =
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
output:
filename: 'bundle.js',
path: path.resolve(__dirname, './public')
,
devtool: "#eval-source-map",
module:
rules: [
test: /.jsx?$/,
exclude: /node_modules/,
use:
loader: 'babel-loader?cacheDirectory=true',
,
test: /.css$/,
loader: "style-loader!css-loader"
,
gif]
,
node:
fs: 'empty'
,
resolve:
extensions: ['.js', '.jsx']
,
externals:
fs: '',
tls: '',
net: '',
dns: '',
readline: ''
;
Upon starting the app with the ./node_modules/.bin/webpack-dev-server --inline --hot I see the following output:

Any suggestions would be greatly appreciated.
Update
I changed name of the file which is an entry point from app.html to index.html in the public folder and also changed the command to start the app to ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot and the app started but the requests to the node server result in 404 errors, the server is not processing requests somehow. I guess that can be because app.js script was not run and so all the middleware was not set up, but I am not sure how to pre-run it or package into the bundle.js. I have two layers though: app.js runs and presents the login page and then redirects to the actual app if the login is successful (it is not needed for the development of course).
Update
I tried using nodemon: How to auto-reload files in Node.js?
By doing the following: nodemon ./bin/www where www is the server script. It is not watching for my changes at all. When I change some of .jsx files, no reloading happens.
Update
I tried to change the entry point in webpack.config.js from:
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
to:
entry:
app: ['babel-polyfill', './app.js']
//vendor: ["react","react-dom"]
,
But in this case when building the app it is giving me the error:

Following the advice here: https://github.com/webpack/webpack/issues/2142
I set target: node in the webpack.config.js. It started giving me another error:

I found the following solution: https://github.com/babel/babel/issues/5268
But after running npm install --save babel-standalone the error remained.
Update
I was able to fix the error by adding .json to the extensions: https://github.com/discordjs/discord.js/issues/2656
Now webpack compiled the project successfully and without any errors, however, when I started it with ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot in the browsers' console I see the error: Uncaught ReferenceError: require is not defined and nothing loads.
Update
I was trying to follow: https://hackernoon.com/full-stack-web-application-using-react-node-js-express-and-webpack-97dbd5b9d708
And it is running fine but when I change the React files, the app is not reloaded. Also babel set ups there messed up my project completely, so I can not build the project now.
reactjs webpack
Help to understand please, previously you had a script that started a node.js server. But what was that../app.jsthat you used? How did you serve react.js app? How was it prebuilt? Also, what do you mean by 'webpack-dev-server is just serving files statically from the topmost folder instead of launching the app.'? DevServer builds the client app and serves the generated static files at the specified (or default8080) port. So what do you mean by 'launching the app' and what exactly are you trying to achieve with devServer?
– GProst
Mar 25 at 23:04
app.js isrequiredin the server./bin/www. The latter starts the server withhttp.createServer(app). Bywebpack-dev-server is just serving files statically from the topmost folder instead of launching the app.I mean that I see root folder file structure and the app is not started. The main goal is to reload the app when I change files, so that not to do manual rebuild and launch.
– Nikita Vlasenko
Mar 25 at 23:08
ah, I think now I got what you meant, thanks
– GProst
Mar 25 at 23:10
I have two layers though- how did you recompile the bundle previously? Manually ranwebpackcommand? Just trying to get the full picture
– GProst
Mar 25 at 23:19
Yep, First I runnpm run webpack, thennode ./bin/www
– Nikita Vlasenko
Mar 25 at 23:32
add a comment |
I was using a simple script before to start a React app but I need to reload, rebuild, and restart everything manually this way which is tedious. Now I am trying to set up webpack-dev-server to do that for me. Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app. Previously I used the following script to start the app (it is working good):
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('nodetest1:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val)
var port = parseInt(val, 10);
if (isNaN(port))
// named pipe
return val;
if (port >= 0)
// port number
return port;
return false;
/**
* Event listener for HTTP server "error" event.
*/
function onError(error)
if (error.syscall !== 'listen')
throw error;
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code)
case 'EACCES':
console.error(bind + ' requires elevated privileges'); process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
The webpack.config.js looks the following way:
var path = require('path');
module.exports =
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
output:
filename: 'bundle.js',
path: path.resolve(__dirname, './public')
,
devtool: "#eval-source-map",
module:
rules: [
test: /.jsx?$/,
exclude: /node_modules/,
use:
loader: 'babel-loader?cacheDirectory=true',
,
test: /.css$/,
loader: "style-loader!css-loader"
,
gif]
,
node:
fs: 'empty'
,
resolve:
extensions: ['.js', '.jsx']
,
externals:
fs: '',
tls: '',
net: '',
dns: '',
readline: ''
;
Upon starting the app with the ./node_modules/.bin/webpack-dev-server --inline --hot I see the following output:

Any suggestions would be greatly appreciated.
Update
I changed name of the file which is an entry point from app.html to index.html in the public folder and also changed the command to start the app to ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot and the app started but the requests to the node server result in 404 errors, the server is not processing requests somehow. I guess that can be because app.js script was not run and so all the middleware was not set up, but I am not sure how to pre-run it or package into the bundle.js. I have two layers though: app.js runs and presents the login page and then redirects to the actual app if the login is successful (it is not needed for the development of course).
Update
I tried using nodemon: How to auto-reload files in Node.js?
By doing the following: nodemon ./bin/www where www is the server script. It is not watching for my changes at all. When I change some of .jsx files, no reloading happens.
Update
I tried to change the entry point in webpack.config.js from:
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
to:
entry:
app: ['babel-polyfill', './app.js']
//vendor: ["react","react-dom"]
,
But in this case when building the app it is giving me the error:

Following the advice here: https://github.com/webpack/webpack/issues/2142
I set target: node in the webpack.config.js. It started giving me another error:

I found the following solution: https://github.com/babel/babel/issues/5268
But after running npm install --save babel-standalone the error remained.
Update
I was able to fix the error by adding .json to the extensions: https://github.com/discordjs/discord.js/issues/2656
Now webpack compiled the project successfully and without any errors, however, when I started it with ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot in the browsers' console I see the error: Uncaught ReferenceError: require is not defined and nothing loads.
Update
I was trying to follow: https://hackernoon.com/full-stack-web-application-using-react-node-js-express-and-webpack-97dbd5b9d708
And it is running fine but when I change the React files, the app is not reloaded. Also babel set ups there messed up my project completely, so I can not build the project now.
reactjs webpack
I was using a simple script before to start a React app but I need to reload, rebuild, and restart everything manually this way which is tedious. Now I am trying to set up webpack-dev-server to do that for me. Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app. Previously I used the following script to start the app (it is working good):
#!/usr/bin/env node
/**
* Module dependencies.
*/
var app = require('../app');
var debug = require('debug')('nodetest1:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val)
var port = parseInt(val, 10);
if (isNaN(port))
// named pipe
return val;
if (port >= 0)
// port number
return port;
return false;
/**
* Event listener for HTTP server "error" event.
*/
function onError(error)
if (error.syscall !== 'listen')
throw error;
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code)
case 'EACCES':
console.error(bind + ' requires elevated privileges'); process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
The webpack.config.js looks the following way:
var path = require('path');
module.exports =
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
output:
filename: 'bundle.js',
path: path.resolve(__dirname, './public')
,
devtool: "#eval-source-map",
module:
rules: [
test: /.jsx?$/,
exclude: /node_modules/,
use:
loader: 'babel-loader?cacheDirectory=true',
,
test: /.css$/,
loader: "style-loader!css-loader"
,
gif]
,
node:
fs: 'empty'
,
resolve:
extensions: ['.js', '.jsx']
,
externals:
fs: '',
tls: '',
net: '',
dns: '',
readline: ''
;
Upon starting the app with the ./node_modules/.bin/webpack-dev-server --inline --hot I see the following output:

Any suggestions would be greatly appreciated.
Update
I changed name of the file which is an entry point from app.html to index.html in the public folder and also changed the command to start the app to ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot and the app started but the requests to the node server result in 404 errors, the server is not processing requests somehow. I guess that can be because app.js script was not run and so all the middleware was not set up, but I am not sure how to pre-run it or package into the bundle.js. I have two layers though: app.js runs and presents the login page and then redirects to the actual app if the login is successful (it is not needed for the development of course).
Update
I tried using nodemon: How to auto-reload files in Node.js?
By doing the following: nodemon ./bin/www where www is the server script. It is not watching for my changes at all. When I change some of .jsx files, no reloading happens.
Update
I tried to change the entry point in webpack.config.js from:
entry:
app: ['babel-polyfill', './views/index.js']
//vendor: ["react","react-dom"]
,
to:
entry:
app: ['babel-polyfill', './app.js']
//vendor: ["react","react-dom"]
,
But in this case when building the app it is giving me the error:

Following the advice here: https://github.com/webpack/webpack/issues/2142
I set target: node in the webpack.config.js. It started giving me another error:

I found the following solution: https://github.com/babel/babel/issues/5268
But after running npm install --save babel-standalone the error remained.
Update
I was able to fix the error by adding .json to the extensions: https://github.com/discordjs/discord.js/issues/2656
Now webpack compiled the project successfully and without any errors, however, when I started it with ./node_modules/.bin/webpack-dev-server --content-base public --inline --hot in the browsers' console I see the error: Uncaught ReferenceError: require is not defined and nothing loads.
Update
I was trying to follow: https://hackernoon.com/full-stack-web-application-using-react-node-js-express-and-webpack-97dbd5b9d708
And it is running fine but when I change the React files, the app is not reloaded. Also babel set ups there messed up my project completely, so I can not build the project now.
reactjs webpack
reactjs webpack
edited Mar 25 at 23:46
Nikita Vlasenko
asked Mar 25 at 19:36
Nikita VlasenkoNikita Vlasenko
95415 silver badges31 bronze badges
95415 silver badges31 bronze badges
Help to understand please, previously you had a script that started a node.js server. But what was that../app.jsthat you used? How did you serve react.js app? How was it prebuilt? Also, what do you mean by 'webpack-dev-server is just serving files statically from the topmost folder instead of launching the app.'? DevServer builds the client app and serves the generated static files at the specified (or default8080) port. So what do you mean by 'launching the app' and what exactly are you trying to achieve with devServer?
– GProst
Mar 25 at 23:04
app.js isrequiredin the server./bin/www. The latter starts the server withhttp.createServer(app). Bywebpack-dev-server is just serving files statically from the topmost folder instead of launching the app.I mean that I see root folder file structure and the app is not started. The main goal is to reload the app when I change files, so that not to do manual rebuild and launch.
– Nikita Vlasenko
Mar 25 at 23:08
ah, I think now I got what you meant, thanks
– GProst
Mar 25 at 23:10
I have two layers though- how did you recompile the bundle previously? Manually ranwebpackcommand? Just trying to get the full picture
– GProst
Mar 25 at 23:19
Yep, First I runnpm run webpack, thennode ./bin/www
– Nikita Vlasenko
Mar 25 at 23:32
add a comment |
Help to understand please, previously you had a script that started a node.js server. But what was that../app.jsthat you used? How did you serve react.js app? How was it prebuilt? Also, what do you mean by 'webpack-dev-server is just serving files statically from the topmost folder instead of launching the app.'? DevServer builds the client app and serves the generated static files at the specified (or default8080) port. So what do you mean by 'launching the app' and what exactly are you trying to achieve with devServer?
– GProst
Mar 25 at 23:04
app.js isrequiredin the server./bin/www. The latter starts the server withhttp.createServer(app). Bywebpack-dev-server is just serving files statically from the topmost folder instead of launching the app.I mean that I see root folder file structure and the app is not started. The main goal is to reload the app when I change files, so that not to do manual rebuild and launch.
– Nikita Vlasenko
Mar 25 at 23:08
ah, I think now I got what you meant, thanks
– GProst
Mar 25 at 23:10
I have two layers though- how did you recompile the bundle previously? Manually ranwebpackcommand? Just trying to get the full picture
– GProst
Mar 25 at 23:19
Yep, First I runnpm run webpack, thennode ./bin/www
– Nikita Vlasenko
Mar 25 at 23:32
Help to understand please, previously you had a script that started a node.js server. But what was that
../app.js that you used? How did you serve react.js app? How was it prebuilt? Also, what do you mean by 'webpack-dev-server is just serving files statically from the topmost folder instead of launching the app.'? DevServer builds the client app and serves the generated static files at the specified (or default 8080) port. So what do you mean by 'launching the app' and what exactly are you trying to achieve with devServer?– GProst
Mar 25 at 23:04
Help to understand please, previously you had a script that started a node.js server. But what was that
../app.js that you used? How did you serve react.js app? How was it prebuilt? Also, what do you mean by 'webpack-dev-server is just serving files statically from the topmost folder instead of launching the app.'? DevServer builds the client app and serves the generated static files at the specified (or default 8080) port. So what do you mean by 'launching the app' and what exactly are you trying to achieve with devServer?– GProst
Mar 25 at 23:04
app.js is
required in the server ./bin/www. The latter starts the server with http.createServer(app). By webpack-dev-server is just serving files statically from the topmost folder instead of launching the app. I mean that I see root folder file structure and the app is not started. The main goal is to reload the app when I change files, so that not to do manual rebuild and launch.– Nikita Vlasenko
Mar 25 at 23:08
app.js is
required in the server ./bin/www. The latter starts the server with http.createServer(app). By webpack-dev-server is just serving files statically from the topmost folder instead of launching the app. I mean that I see root folder file structure and the app is not started. The main goal is to reload the app when I change files, so that not to do manual rebuild and launch.– Nikita Vlasenko
Mar 25 at 23:08
ah, I think now I got what you meant, thanks
– GProst
Mar 25 at 23:10
ah, I think now I got what you meant, thanks
– GProst
Mar 25 at 23:10
I have two layers though - how did you recompile the bundle previously? Manually ran webpack command? Just trying to get the full picture– GProst
Mar 25 at 23:19
I have two layers though - how did you recompile the bundle previously? Manually ran webpack command? Just trying to get the full picture– GProst
Mar 25 at 23:19
Yep, First I run
npm run webpack, then node ./bin/www– Nikita Vlasenko
Mar 25 at 23:32
Yep, First I run
npm run webpack, then node ./bin/www– Nikita Vlasenko
Mar 25 at 23:32
add a comment |
1 Answer
1
active
oldest
votes
Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app.
As you guessed correctly this was due to you had
app.htmlinstead ofindex.htmland devServer didn't know which file to load by default. You can solve it as you did by renaming the file or you can set the following option inwebpack.config.js:devServer: index: 'app.html'- see this for details. But I'd personally rename it as you did.
the app started but the requests to the node server result in 404 errors
This could be for 2 reasons. First, your server wasn't up, you had to start it as you started it before (
node ./bin/www) since devServer just serves static client assets and it doesn't have any of your server logic. Second, even after you start it you will probably have 404 errors as well. This depends on how you specified URLs. If you specified them as an absolute path (likehttp://localhost:3000/my-endpoint/path) then they should hit your main server normally but if you specified them as a relative path (/my-endpoint/path) then they will be sent tohttp://localhost:8080/my-endpoint/path(i.e. devServer host/port instead of your main server). To solve this you can specify proxy settings in yourwebpack.config:devServer:
proxy: [
context: ['/my-endpoint'], // endpoints which you want to proxy
target: 'http://localhost:3000' // your main server address
]See this for details.
Well, other errors you had because you started to bundle your sever (target: node) instead of your client app as you correctly started to do at first. When you successfully bundled your server app of course you couldn't open it in a browser, since it is Node.js code (browser doesn't have require method for example, hence the error)
EDIT:
Missed a comment about --content-base public. Yes, you also have to specify the folder that you want devServer to serve if you have some prebuilt assets like app.html of yours. Another option is to use html-webpack-plugin which will generate index.html dynamically by webpack so devServer knows where to take it from (from the memory where devServer keeps all generated assets).
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I tried it withnodemonand just withnodeand neither of them work
– Nikita Vlasenko
Mar 26 at 0:49
1
If you runnodemon ./bin/wwwit will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance onlocalhost:3000and devServer is running onlocalhost:8080then the app will reload only if you open the latest url.
– GProst
Mar 26 at 1:07
1
ah... damn... you use--hotand this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing--hotoption. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeahreact-hot-loaderis what you should use in this case with react
– GProst
Mar 26 at 1:12
1
Ok, fixed it! The issue was that I did not follow your advice, but leftdevServerconfiguration from the link: hackernoon.com/…. Thank a lot!
– Nikita Vlasenko
Mar 26 at 1:16
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345229%2fcant-set-up-webpack-dev-server-to-start-react-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app.
As you guessed correctly this was due to you had
app.htmlinstead ofindex.htmland devServer didn't know which file to load by default. You can solve it as you did by renaming the file or you can set the following option inwebpack.config.js:devServer: index: 'app.html'- see this for details. But I'd personally rename it as you did.
the app started but the requests to the node server result in 404 errors
This could be for 2 reasons. First, your server wasn't up, you had to start it as you started it before (
node ./bin/www) since devServer just serves static client assets and it doesn't have any of your server logic. Second, even after you start it you will probably have 404 errors as well. This depends on how you specified URLs. If you specified them as an absolute path (likehttp://localhost:3000/my-endpoint/path) then they should hit your main server normally but if you specified them as a relative path (/my-endpoint/path) then they will be sent tohttp://localhost:8080/my-endpoint/path(i.e. devServer host/port instead of your main server). To solve this you can specify proxy settings in yourwebpack.config:devServer:
proxy: [
context: ['/my-endpoint'], // endpoints which you want to proxy
target: 'http://localhost:3000' // your main server address
]See this for details.
Well, other errors you had because you started to bundle your sever (target: node) instead of your client app as you correctly started to do at first. When you successfully bundled your server app of course you couldn't open it in a browser, since it is Node.js code (browser doesn't have require method for example, hence the error)
EDIT:
Missed a comment about --content-base public. Yes, you also have to specify the folder that you want devServer to serve if you have some prebuilt assets like app.html of yours. Another option is to use html-webpack-plugin which will generate index.html dynamically by webpack so devServer knows where to take it from (from the memory where devServer keeps all generated assets).
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I tried it withnodemonand just withnodeand neither of them work
– Nikita Vlasenko
Mar 26 at 0:49
1
If you runnodemon ./bin/wwwit will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance onlocalhost:3000and devServer is running onlocalhost:8080then the app will reload only if you open the latest url.
– GProst
Mar 26 at 1:07
1
ah... damn... you use--hotand this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing--hotoption. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeahreact-hot-loaderis what you should use in this case with react
– GProst
Mar 26 at 1:12
1
Ok, fixed it! The issue was that I did not follow your advice, but leftdevServerconfiguration from the link: hackernoon.com/…. Thank a lot!
– Nikita Vlasenko
Mar 26 at 1:16
|
show 1 more comment
Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app.
As you guessed correctly this was due to you had
app.htmlinstead ofindex.htmland devServer didn't know which file to load by default. You can solve it as you did by renaming the file or you can set the following option inwebpack.config.js:devServer: index: 'app.html'- see this for details. But I'd personally rename it as you did.
the app started but the requests to the node server result in 404 errors
This could be for 2 reasons. First, your server wasn't up, you had to start it as you started it before (
node ./bin/www) since devServer just serves static client assets and it doesn't have any of your server logic. Second, even after you start it you will probably have 404 errors as well. This depends on how you specified URLs. If you specified them as an absolute path (likehttp://localhost:3000/my-endpoint/path) then they should hit your main server normally but if you specified them as a relative path (/my-endpoint/path) then they will be sent tohttp://localhost:8080/my-endpoint/path(i.e. devServer host/port instead of your main server). To solve this you can specify proxy settings in yourwebpack.config:devServer:
proxy: [
context: ['/my-endpoint'], // endpoints which you want to proxy
target: 'http://localhost:3000' // your main server address
]See this for details.
Well, other errors you had because you started to bundle your sever (target: node) instead of your client app as you correctly started to do at first. When you successfully bundled your server app of course you couldn't open it in a browser, since it is Node.js code (browser doesn't have require method for example, hence the error)
EDIT:
Missed a comment about --content-base public. Yes, you also have to specify the folder that you want devServer to serve if you have some prebuilt assets like app.html of yours. Another option is to use html-webpack-plugin which will generate index.html dynamically by webpack so devServer knows where to take it from (from the memory where devServer keeps all generated assets).
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I tried it withnodemonand just withnodeand neither of them work
– Nikita Vlasenko
Mar 26 at 0:49
1
If you runnodemon ./bin/wwwit will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance onlocalhost:3000and devServer is running onlocalhost:8080then the app will reload only if you open the latest url.
– GProst
Mar 26 at 1:07
1
ah... damn... you use--hotand this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing--hotoption. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeahreact-hot-loaderis what you should use in this case with react
– GProst
Mar 26 at 1:12
1
Ok, fixed it! The issue was that I did not follow your advice, but leftdevServerconfiguration from the link: hackernoon.com/…. Thank a lot!
– Nikita Vlasenko
Mar 26 at 1:16
|
show 1 more comment
Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app.
As you guessed correctly this was due to you had
app.htmlinstead ofindex.htmland devServer didn't know which file to load by default. You can solve it as you did by renaming the file or you can set the following option inwebpack.config.js:devServer: index: 'app.html'- see this for details. But I'd personally rename it as you did.
the app started but the requests to the node server result in 404 errors
This could be for 2 reasons. First, your server wasn't up, you had to start it as you started it before (
node ./bin/www) since devServer just serves static client assets and it doesn't have any of your server logic. Second, even after you start it you will probably have 404 errors as well. This depends on how you specified URLs. If you specified them as an absolute path (likehttp://localhost:3000/my-endpoint/path) then they should hit your main server normally but if you specified them as a relative path (/my-endpoint/path) then they will be sent tohttp://localhost:8080/my-endpoint/path(i.e. devServer host/port instead of your main server). To solve this you can specify proxy settings in yourwebpack.config:devServer:
proxy: [
context: ['/my-endpoint'], // endpoints which you want to proxy
target: 'http://localhost:3000' // your main server address
]See this for details.
Well, other errors you had because you started to bundle your sever (target: node) instead of your client app as you correctly started to do at first. When you successfully bundled your server app of course you couldn't open it in a browser, since it is Node.js code (browser doesn't have require method for example, hence the error)
EDIT:
Missed a comment about --content-base public. Yes, you also have to specify the folder that you want devServer to serve if you have some prebuilt assets like app.html of yours. Another option is to use html-webpack-plugin which will generate index.html dynamically by webpack so devServer knows where to take it from (from the memory where devServer keeps all generated assets).
Somehow just starting the webpack-dev-server by ./node_modules/.bin/webpack-dev-server --inline --hot is just serving files statically from the topmost folder instead of launching the app.
As you guessed correctly this was due to you had
app.htmlinstead ofindex.htmland devServer didn't know which file to load by default. You can solve it as you did by renaming the file or you can set the following option inwebpack.config.js:devServer: index: 'app.html'- see this for details. But I'd personally rename it as you did.
the app started but the requests to the node server result in 404 errors
This could be for 2 reasons. First, your server wasn't up, you had to start it as you started it before (
node ./bin/www) since devServer just serves static client assets and it doesn't have any of your server logic. Second, even after you start it you will probably have 404 errors as well. This depends on how you specified URLs. If you specified them as an absolute path (likehttp://localhost:3000/my-endpoint/path) then they should hit your main server normally but if you specified them as a relative path (/my-endpoint/path) then they will be sent tohttp://localhost:8080/my-endpoint/path(i.e. devServer host/port instead of your main server). To solve this you can specify proxy settings in yourwebpack.config:devServer:
proxy: [
context: ['/my-endpoint'], // endpoints which you want to proxy
target: 'http://localhost:3000' // your main server address
]See this for details.
Well, other errors you had because you started to bundle your sever (target: node) instead of your client app as you correctly started to do at first. When you successfully bundled your server app of course you couldn't open it in a browser, since it is Node.js code (browser doesn't have require method for example, hence the error)
EDIT:
Missed a comment about --content-base public. Yes, you also have to specify the folder that you want devServer to serve if you have some prebuilt assets like app.html of yours. Another option is to use html-webpack-plugin which will generate index.html dynamically by webpack so devServer knows where to take it from (from the memory where devServer keeps all generated assets).
edited Mar 26 at 0:13
answered Mar 25 at 23:53
GProstGProst
2,8172 gold badges11 silver badges36 bronze badges
2,8172 gold badges11 silver badges36 bronze badges
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I tried it withnodemonand just withnodeand neither of them work
– Nikita Vlasenko
Mar 26 at 0:49
1
If you runnodemon ./bin/wwwit will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance onlocalhost:3000and devServer is running onlocalhost:8080then the app will reload only if you open the latest url.
– GProst
Mar 26 at 1:07
1
ah... damn... you use--hotand this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing--hotoption. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeahreact-hot-loaderis what you should use in this case with react
– GProst
Mar 26 at 1:12
1
Ok, fixed it! The issue was that I did not follow your advice, but leftdevServerconfiguration from the link: hackernoon.com/…. Thank a lot!
– Nikita Vlasenko
Mar 26 at 1:16
|
show 1 more comment
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I tried it withnodemonand just withnodeand neither of them work
– Nikita Vlasenko
Mar 26 at 0:49
1
If you runnodemon ./bin/wwwit will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance onlocalhost:3000and devServer is running onlocalhost:8080then the app will reload only if you open the latest url.
– GProst
Mar 26 at 1:07
1
ah... damn... you use--hotand this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing--hotoption. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeahreact-hot-loaderis what you should use in this case with react
– GProst
Mar 26 at 1:12
1
Ok, fixed it! The issue was that I did not follow your advice, but leftdevServerconfiguration from the link: hackernoon.com/…. Thank a lot!
– Nikita Vlasenko
Mar 26 at 1:16
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I set it up, it is running without any issues shown in the console/node terminal but the React app is not reloading when I modify files
– Nikita Vlasenko
Mar 26 at 0:40
I tried it with
nodemon and just with node and neither of them work– Nikita Vlasenko
Mar 26 at 0:49
I tried it with
nodemon and just with node and neither of them work– Nikita Vlasenko
Mar 26 at 0:49
1
1
If you run
nodemon ./bin/www it will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance on localhost:3000 and devServer is running on localhost:8080 then the app will reload only if you open the latest url.– GProst
Mar 26 at 1:07
If you run
nodemon ./bin/www it will watch your server files, not client, so it won't rebuild the bundle. So devServer compiled files successfully? Can you see in that webpack-dev-server rebuilds files when they're changed in the termincal? Are you sure you open the app at the devServer URL and not your main server? I mean if you have your main server running for instance on localhost:3000 and devServer is running on localhost:8080 then the app will reload only if you open the latest url.– GProst
Mar 26 at 1:07
1
1
ah... damn... you use
--hot and this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing --hot option. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeah react-hot-loader is what you should use in this case with react– GProst
Mar 26 at 1:12
ah... damn... you use
--hot and this is hot module replacement. Sorry, didn't pay attention. So there won't be page reloads. Try removing --hot option. Actually hot module replacement even nicer than page reload, but more tricky. It will update the client code even without the page reload. But you should read about it first, how to configure etc, probably will require some additional configs, hard to say. But yeah react-hot-loader is what you should use in this case with react– GProst
Mar 26 at 1:12
1
1
Ok, fixed it! The issue was that I did not follow your advice, but left
devServer configuration from the link: hackernoon.com/…. Thank a lot!– Nikita Vlasenko
Mar 26 at 1:16
Ok, fixed it! The issue was that I did not follow your advice, but left
devServer configuration from the link: hackernoon.com/…. Thank a lot!– Nikita Vlasenko
Mar 26 at 1:16
|
show 1 more comment
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345229%2fcant-set-up-webpack-dev-server-to-start-react-app%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Help to understand please, previously you had a script that started a node.js server. But what was that
../app.jsthat you used? How did you serve react.js app? How was it prebuilt? Also, what do you mean by 'webpack-dev-server is just serving files statically from the topmost folder instead of launching the app.'? DevServer builds the client app and serves the generated static files at the specified (or default8080) port. So what do you mean by 'launching the app' and what exactly are you trying to achieve with devServer?– GProst
Mar 25 at 23:04
app.js is
requiredin the server./bin/www. The latter starts the server withhttp.createServer(app). Bywebpack-dev-server is just serving files statically from the topmost folder instead of launching the app.I mean that I see root folder file structure and the app is not started. The main goal is to reload the app when I change files, so that not to do manual rebuild and launch.– Nikita Vlasenko
Mar 25 at 23:08
ah, I think now I got what you meant, thanks
– GProst
Mar 25 at 23:10
I have two layers though- how did you recompile the bundle previously? Manually ranwebpackcommand? Just trying to get the full picture– GProst
Mar 25 at 23:19
Yep, First I run
npm run webpack, thennode ./bin/www– Nikita Vlasenko
Mar 25 at 23:32