Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running the server does not compile files or reload page in windows. #155

Closed
quantuminformation opened this issue Apr 15, 2015 · 73 comments
Closed

Comments

@quantuminformation
Copy link

From the docs it says:

It binds a small express server on localhost:8080 which serves your static assets as well as the bundle (compiled automatically). It automatically updates the browser page when a bundle is recompiled (socket.io). Open http://localhost:8080/webpack-dev-server/bundle in your browser.

However if I run it this doesn't happen: I just get the following, but when I go to the serving URL I still have my old code.

C:\Users\Laptop\WebstormProjects\wirejs-client>npm run start

> [email protected] start C:\Users\Laptop\WebstormProjects\wirejs-client
> webpack-dev-server

http://localhost:8080/webpack-dev-server/
webpack result is served from /
content is served from C:\Users\Laptop\WebstormProjects\wirejs-client
webpack: wait until bundle finished: /webpack-dev-server/
Hash: 25bf81a3ab16cfec1760
Version: webpack 1.8.4
Time: 8688ms
        Asset     Size  Chunks             Chunk Names
    bundle.js  4.37 kB       0  [emitted]  main
bundle.js.map     4 kB       0  [emitted]  main
chunk    {0} bundle.js, bundle.js.map (main) 2.69 kB [rendered]
    [0] ./app/main.js 295 bytes {0} [built]
    [1] ./app/wirejs-client.js 2.39 kB {0} [built]
webpack: bundle is now VALID.

@quantuminformation
Copy link
Author

The closest I can get to what I want, is to run these in separate terminals

webpack --watch
webpack-dev-server

@MrOrz
Copy link
Contributor

MrOrz commented Apr 17, 2015

Maybe webpack-dev-server compiles your code, but did not know when to send them to the browser. Also, webpack-dev-server stores the compiled bundle in memory, thus the old copy remains in the file system. That's why your browser are always getting the old files.

Webpack-dev-server reads output.publicPath in the config. Whenever browser sends a request to get file under that path, it tries to return the compiled bundle.

If you access your bundle.js using <script src="/build/bundle.js"></script>, you may try the following in the CLI, which should be equivalent to setting up output.publicPath in a config file:

webpack-dev-server --output-public-path=/build/

@jasonmacdonald
Copy link

Same here, I get neither change detection or window reloading. It doesn't recompile on changes, and doesn't reload the browser. No errors. :(

I can't get "webpack --watch" to do detect changes either

@quantuminformation
Copy link
Author

@MrOrz thanks but I still have to manually refresh the page.

@MrOrz
Copy link
Contributor

MrOrz commented Apr 21, 2015

@quantuminformation If you want it to live reload, you'll need to setup hot mode as instructed here: http://webpack.github.io/docs/webpack-dev-server.html#hot-mode

@chiefjester
Copy link

same issue here, it works in osx, same config doesn't work on windows 8.1.
I was having problem when using the hash option, it started working if I just use bundle.js without a hash.

@rictorres
Copy link

I'm having the same issue. For now I'm running webpack-dev-server inside Vagrant.

UPDATE: not working on Vagrant, probably because it's a shared folder :{

@rictorres
Copy link

Using Webpack inside Vagrant on a non-shared folder works fine.

@quantuminformation
Copy link
Author

@MrOrz thanks that works, however on windows chrome keeps crashing :(

@quantuminformation
Copy link
Author

Closing anyway as the hot mode acheives what I need, however it seems like a lot of extra config to me.

@luiz-gustavo-agostinho
Copy link

@rictorres I have the same here over Vagrant with shared folder. Have you found a way?

@kzima
Copy link

kzima commented Aug 12, 2015

if you only care about browser reload and don't need to set up hot mode than follow this workaround:

  1. remove 'webpack/hot/dev-server' from your entry object in wepack config, otherwise you will get this error in your browser console:
    [HMR] Hot Module Replacement is disabled.
  2. in one terminal run webpack --watch
  3. in second terminal run webpack-dev-server

That's it. Now your browser should reload every time you modify something in your code.
Hopefully this helps.

@rictorres
Copy link

@agostlg I'm running Webpack through Gulp :)

@hyzhak
Copy link

hyzhak commented Nov 1, 2015

doesn't recompile and doesn't reload. I'm using shared folders in Vagrant

@scott2449
Copy link

While vbox shared folders update content they do not update the mtime of the file. If I touch the file on the guest machine it then reloads. I'm assuming inotify (or equivalent doesn't pick up these changes). More active scanning or a vbox fix seem like the only route.

@quantuminformation
Copy link
Author

Shall I reopen this?

@alexsandro-xpt
Copy link

Same problem here I'm using Windows 8.1 and Gulp.

In Web Development Tools at Chrome in Network tab, the websocket only in pending status and return 0 bytes of size.

@alexsandro-xpt
Copy link

I don't know, but now its working now for me at Windows 8.1... feel free to see https://github.com/alexsandro-xpt/DemoWebPackAngularGulp

@pvasek
Copy link

pvasek commented Nov 23, 2015

I had the same issue. The reason was that I built the output files with webpack first and than try to run the dev server. It seems that in my configuration the dev server served the files from disk no matter that in memory was something else (I could see reinvalidating bundles after changes). After removing these files from disk everything started to work again.

@Jakobud
Copy link

Jakobud commented Nov 24, 2015

I have found the solution for this on Vagrant shared folders:

# webpack-dev-server --watch-poll

Now my bundle will properly get rebuilt.

@finbarmaginn
Copy link

webpack-dev-server --watch-poll works for us on win 8.1

@dryoma
Copy link

dryoma commented Dec 6, 2015

I had a similar problem on Windows. webpack-dev-server in one of the projects just wouldn't react to changes to .js files. In the end the reason was quite stupid: you just can't use certain symbols in a path to the project. For example, if there are braces there ((), []), the changes won't be seen by webpack-dev-server; with an ! it won't even start. Maybe there are more, just didn't bother digging.

Hope someone finds this helpful.

@nathanborror
Copy link

Having the same problem due to Dropbox using () in its naming convention for Dropbox for Business accounts: ~/Dropbox (business name)/. Tried symlinking but webpack ignores the symlink and uses the original path.

@fireproofsocks
Copy link

Same problem... none of the above solutions have worked for me, and eliminating the caveats (e.g. Dropbox) has also not gotten the behavior to work as expected.

@vianvio
Copy link

vianvio commented Dec 20, 2015

By using --hot, you need to specify the output.publicPath in your webpack.config.js file.
ie. if you have ./build/bundle.js, you need to set output.publicPath as '/build/'. Then it will auto recompile and reload the page.
Hope this helps

@oliverjanik
Copy link

Just followed the getting started tutorial. Webpack dev server does not reload the browser after recompiling. I'm on Win 10

It seems a common pattern with any node project. Things break apart even before finishing introduction.

Edit:
Here's what works for me: webpack-dev-server --progress --inline

@yonixw
Copy link

yonixw commented Jun 16, 2016

Just want to say that a solution that worked for me was to use git bash for windwos.
Running the watcher from there worked perfectly.

Win 7 64 Bit

@NickSevens
Copy link

NickSevens commented Jun 16, 2016

Hi, I've got the same issue (I think) on Windows 10.
Tried running in git bash, but without success...

Edit: fixed it by adding windows-style path separators to devServer.contentBase property:

module.exports = {
  devServer: {
    contentBase: '.\\src\\'
  }
}

@dqisme
Copy link

dqisme commented Jun 18, 2016

Awesome! Works fine on Windows 10.
by the way, it is recommended that using path.join for cross-platform to deal with all the path stuff.

@NickSevens
Copy link

Indeed. Changed it to that afterwards :) made it easier for cross platform dev.

@ghost
Copy link

ghost commented Jun 19, 2016

Thanks @nathanborror for your hint about the Dropbox for Business's path convention, that solved it for me.

@eromoe
Copy link

eromoe commented Jun 20, 2016

A project I used has below code

const path = require('path');
const express = require('express');
const webpack = require('webpack');
const config = require('./webpack.config.dev');

const app = express();
const compiler = webpack(config);

app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  publicPath: config.output.publicPath
}));

app.use(require('webpack-hot-middleware')(compiler));

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});

It use npm run dev to start, hot reload work on windows 8.1 but windows 7
What's the problem?
I don't know much about webpack, ..

@rajyavardhanp
Copy link

rajyavardhanp commented Jul 10, 2016

webpack-dev-server --content-base ***** --inline --hot
**** >> should be your output folder
./dist or wherever you are building the output

If you don't want to reload the page every time, for most platforms localhost:8080 is enough, else check in localhost:8080/webpack-dev-server/index.html

@Ajaybhardwaj7
Copy link

Ajaybhardwaj7 commented Jul 20, 2016

Here is the sample working app which I have created after two days of struggle. I have used the webpack dev server API method. https://github.com/Ajaybhardwaj7/webpack-react-sample

@blackhawk389
Copy link

@quantuminformation I have successfully launched recompiled file(not manually refresh), how? seting path to dist folder and devServer: { contentBase: "./dist", }, doing this

@jshbrntt
Copy link

jshbrntt commented Aug 1, 2016

Moved from OS X to Windows 10 and now webpack-dev-server is not detecting changes and rebuilding the bundle. I'm using Atom so there's no safe write, so that shouldn't be the problem.

I've attempted most solutions in this issue to no avail.

  • Inline
  • Hot
  • Watch - Use Polling

Here's my config see devServer.

@Kekesed
Copy link

Kekesed commented Aug 4, 2016

same here, i have the exact same problem with @synthecypher

@lostpebble
Copy link

lostpebble commented Aug 5, 2016

Depending on what editor you're using, that could be causing the issue. Just found out that WebStorm was giving me this problem from Windows but not on Ubuntu (the settings must have been different on each).

The setting I had to disable which made all the difference was use "safe write" (found in Appearance & Behaviour > System Settings), which saves changes first to a temporary file. Saving like that doesn't get picked up by webpack of course, was the cause of much frustration.

@amcdnl
Copy link

amcdnl commented Aug 6, 2016

I can't get it to work either, everything loads fine but upon refresh auto or even manual it does not reflect updates. My config is: https://github.com/swimlane/angular2-data-table/blob/master/webpack.config.js

@AurelioDeRosa
Copy link

AurelioDeRosa commented Aug 9, 2016

I've had the same problem with webpack 1.13.1 and webpack-dev-server 1.14.1 on Windows 10. Adding the following code to the webpack.config.js file solved the issue:

plugins: [
   new webpack.OldWatchingPlugin()
]

@jshbrntt
Copy link

@Kekesed I managed to get it working it appears that it was caused by the paths not being correct for Windows. Wrap any applicable paths in path.resolve and path.join should do the job.

Here's the updated config feel free to clone my repo and test for yourselves.

@cooervo
Copy link

cooervo commented Aug 15, 2016

This is what worked for me in windows 10:

//Webpack.config.js file:

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: "./js/client.js",
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
        }
      }
    ]
  },
  output: {
    path: path.join(__dirname, '/src/'),
    publicPath: '/src/', // instead of publicPath: '/build/'
    filename: 'client.min.js'
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

Go to cmd and type: webpack-dev-server --watch-poll

This is my dir structure:
image

In browser go to: http://localhost:8080/webpack-dev-server/

@sushicutta
Copy link

Windows 10 - IntelliJ Ultimate (aka Webstrom) this solved it for me:

<< Depending on what editor you're using, that could be causing the issue. Just found out that WebStorm was giving me this problem from Windows but not on Ubuntu (the settings must have been different on each).

The setting I had to disable which made all the difference was use "safe write" (found in Appearance & Behaviour > System Settings), which saves changes first to a temporary file. Saving like that doesn't get picked up by webpack of course, was the cause of much frustration. >> Thanks to @lostpebble

@SpaceK33z
Copy link
Member

Closing because there are several answers to the problem. Some of these issues are also documented.

If anyone still has an issue, feel free to create a new issue.

@alb3rto269
Copy link

alb3rto269 commented Sep 15, 2016

This might be related to: #324
The solution posted in that other issue solved my problem.

@fazalrasel
Copy link

Those using Polling, watch for RAM use...

@An-Dang
Copy link

An-Dang commented Oct 4, 2016

I used Intellij 2016.2.3 on Win1 and I've also solved the problem with ctrl + s.

@awesomund
Copy link

Also experienced this problem with webpack-hot-middleware on my own express-server.

Adding watchOptions to my webpack-dev-middleware-options solved this for me.

relevant part of my server.js:

app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  publicPath: webpackConfig.output.publicPath,
  watchOptions: {
    aggregateTimeout: 300,
    poll: 1000
  }
}));

@dharmesh-khandelwal
Copy link

@dryoma Thank You!! I removed () from the folder name, and live reloading works :)

@CocaCola183
Copy link

@wmira Save my life

@jartaud
Copy link

jartaud commented Oct 19, 2016

@awesomund works for me. Vue Cli webpack, Laravel Homestead, Win10,

@Kielan
Copy link

Kielan commented Oct 23, 2016

Crazy this issue has been closed a year ago, tons of people on many machines still have it, and no solution by authors. On osx and have the same problem.

I know one could say "it's open source you should fix it"

@SpaceK33z
Copy link
Member

There is not really a clear issue here, various people have posted their various issues here. If you still have a problem with reloading, please create a new issue and fill in all details. Locking this thread.

@webpack webpack locked and limited conversation to collaborators Oct 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests