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

webpack watch mode not working.... #2949

Closed
mastrauckas opened this issue Sep 3, 2016 · 37 comments
Closed

webpack watch mode not working.... #2949

mastrauckas opened this issue Sep 3, 2016 · 37 comments

Comments

@mastrauckas
Copy link

General Information:
webpack version: 1.13.2
OS: Windows 10 Anniversary Update and webpack is running in Windows Subsystem for Linux(The new bash on Ubuntu)

I"m trying to run webpack in watch mode by using:

webpack --watch

and by also setting watch mode in config:

context: path.join(__dirname, '/src'),
devtool: debug ? 'inline-sourcemap' : null,
entry: './js-src/scripts.js',
watch: true,
module: {

All webpack does is run the transpiler and exit.
Example of output when running watch mode:

Hash: 045070ba2ed9ce40edf7
Version: webpack 1.13.2
Time: 2146ms
         Asset     Size  Chunks             Chunk Names
scripts.min.js  1.89 MB       0  [emitted]  main
    + 172 hidden modules

I'm not sure what i'm doing incorrect?

@TheLarkInn
Copy link
Member

  1. Could you please first post your question on stack overflow before you post here. Our issue template clearly encourages submitters to submit their questions/support there so that you have more accessible support. When you have submitted the question to stackoverflow, please provide the link there for easier access.
  2. Could you please provide your full webpack configuration.

@mastrauckas
Copy link
Author

mastrauckas commented Sep 4, 2016

Since I think it's a possible issue I think this is the appropriate place because it might be an issue.: Full webpack config:

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

module.exports = {
  context: path.join(__dirname, '/src'),
  devtool: debug ? 'inline-sourcemap' : null,
  entry: './js-src/scripts.js',
  watch: true,
  module: {
    loaders: [
      {
        test: /.js?$/,
        exclude: /(node_modules)|(bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0']
        }
      }
    ]
  },
  output: {
    path: path.join(__dirname, '/src/wwwroot/static/js'),
    filename: 'scripts.min.js'
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  ],
};

Thanks!

@sokra
Copy link
Member

sokra commented Sep 5, 2016

OS: Windows 10 Anniversary Update and webpack is running in Windows Subsystem for Linux(The new bash on Ubuntu)

Probably chokidar has an issue with this...

@TheLarkInn
Copy link
Member

Their issue list has a few maybe related things. @mastrauckas is there any additional details that you think might be beneficial that we (you could also as well) could submit to @paulmillr?

@mastrauckas
Copy link
Author

@TheLarkInn I have no additional information. Should I just put a ticket on their issue list and refer back to this ticket?

@paulmillr
Copy link

@mastercactapus I would be glad to help you (i've created chokidar). Are you able to set up a demo git repo that makes it easy to replicate the issue?

@mastrauckas
Copy link
Author

@paulmillr I can pull down any demo you want me too from git and run it. I might not be able to do it until tomorrow though.

@TheLarkInn
Copy link
Member

@paulmillr thank you very much!!

@rafde
Copy link
Contributor

rafde commented Sep 6, 2016

@mastrauckas I think you have a typo
devtool: debug ? 'inline-sourcemap' : null,
should be
devtool: debug ? 'inline-source-map' : null,

@mastrauckas
Copy link
Author

@rafde Thanks for noticing that. I'll fix that tonight and see if it fixes the issue.

@mastrauckas
Copy link
Author

@rafde That didn't fix the issue. @paulmillr what did you want me to demo?

@paulmillr
Copy link

Would be great to have a demo repository where i'll be able to reproduce the issue simply without hassle and messing with configs.

@eteeselink
Copy link

@paulmillr FWIW, I experience the exact same thing on a number of webpack projects in Windows Subsystem for Linux, which have wildly varying configs. Therefore I'm not sure prepping any particular repo will help.

All that said, I share Sokra's hunch that this is either in chokidar or simply a core bug in this fancy new Windows feature. So I cloned chokidar, ran tests, got 19 passes and 76 failures (gist: https://gist.github.com/eteeselink/0c7394eab588d0851d8633cc0ade7c3f). Running the same tests on plain windows gives 0 test failures. Node 6.5.0 on both "platforms". Removed node_modules and re-did npm install before running tests on either system.

@mastrauckas
Copy link
Author

mastrauckas commented Sep 7, 2016

@paulmillr like @eteeselink said it might be an issue in the Windows Subsystem for Linux,. Here is a demo project https://github.com/mastrauckas/webpack-issue that is having the issue. I you need me to do anything else please let me know.

@paulmillr
Copy link

What about webpack tests? Does everything pass on the subsystem?

@mastrauckas
Copy link
Author

mastrauckas commented Sep 10, 2016

@paulmillr here is the result of running npm test for webpack.

@mastrauckas
Copy link
Author

mastrauckas commented Sep 10, 2016

@paulmillr here is also the result of running npm test on chokidar

@paulmillr
Copy link

68 failing tests for webpack.

Basically this means Windows subsystem for Linux is broken and shitty. I'll see what we can do here but a more robust solution would be to cease using it until Windows developers would fix all issues.

@eteeselink
Copy link

@paulmillr that's a perfectly valid solution for me, FWIW. WSL is beta so some incompatibilities are to be expected, i guess.

I just discovered it's a known bug in WSL: microsoft/WSL#216. If I were @sokra I'd close this bug until MS fixes inotify.

For people who find this webpack issue, the issue linked above lets you vote on this on UserVoice: https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13469097-support-for-filesystem-watchers-like-inotify

@mastrauckas
Copy link
Author

I'm going to reply to the bug @eteeselink put a like to.

@bmayen
Copy link

bmayen commented Oct 10, 2016

microsoft/WSL#216 has been closed

@Eccenux
Copy link

Eccenux commented Oct 15, 2016

I've unistalled Bash on Windows 10 and webpack --watch still isn't working. Even with a very simple config like:

module.exports = {
    entry: './entry.js',
    output: {
        path: __dirname,
        filename: "bundle.js"
    }
};

Path to project is d:\_WWW\!_serwer_root\_test\webpack (if that is important). And entry.js just contains:

console.log('123');

@Eccenux
Copy link

Eccenux commented Oct 15, 2016

Nevermind... The problem was the ! in the directory name :-/

@bebraw
Copy link
Contributor

bebraw commented Dec 24, 2016

Moved to webpack/watchpack#43.

@lahdo
Copy link

lahdo commented Feb 13, 2017

Try this workaround:

Add this to your webpack configuration file:

    watchOptions: {
        poll: true
    },

@swordman1205
Copy link

swordman1205 commented Jul 29, 2017

watchOptions: {
poll: true
}

Thank you. This solution works for me.

@ankitrg
Copy link

ankitrg commented Aug 11, 2017

I am on webpack 3, and I have poll option enabled, still Webpack picks up first few writes and then doesn't do that. I have tried saving the files via emacs and atom.

@dzwiedziu-nkg
Copy link

I have similar problem on Linux Mint 18.2. After fix inotify issue works fun :)

@toididau456
Copy link

@lahdo thank you!

@vladshlianin
Copy link

@lahdo I know, It's a ghost thread, but still - thank you, I've really struggled with this issue!

@hijackthegit
Copy link

@lahdo thank you too, saved my day, literally!

@barisusakli
Copy link

For anyone stumbling upon this when using the node API, having

watchOptions: {
  poll: true
}

In the webpack config didn't work for me, I had to feed it into the compiler.watch function, not sure if this is intended.

const webpack = require('webpack');

const compiler = webpack({
  // these options do not seem to effect compiler.watch
  watchOptions: { 
    poll: true,
  },
});

const watching = compiler.watch({
  poll: true // this works
}, (err, stats) => { // Stats Object
  console.log(stats);
});

@ChrisTsou
Copy link

For googlers,
On wsl 2 you have to set poll, poll: 1000 worked for me.

@zatloeri
Copy link

zatloeri commented Oct 11, 2020

This just happened to me (Putting it here because this is where it led me).
The compilation starts and finishes without any error, but it does not continue to watch for changes.
It acts as if watch is disabled.

My webpack.config.js is:

module.exports = () => ({
    entry: path.resolve(__dirname, 'src/index.ts'),
    mode: NODE_ENV,
    watch: true,
    target: 'node',
...
// rest of config (uninportant I think)
...
}

And I am running webpack via NODE_ENV=development webpack

I found the problem in my case is combination of

"webpack": "^4.44.2",
"webpack-cli": "^4.0.0",

If I change webpack-cli to version "^3.3.12" and update my deps, then everything works as expected.
Don't know why this is, but I hope it can help somebody solving the problem for themselves.
Also should mention that I am using:

yarn version - 1.22.4
node version - v14.13.0

@alexander-akait
Copy link
Member

@zatloeri Please create reproducible test repo and open an issue in webpack-cli

@miadabdi
Copy link

I had this problem, just updated webpack-cli from 4.0.0 to 4.1.0 and it fixed it!

@aaronamm
Copy link

@lahdo Thank you so much. It works.
Here is part of my Webpack setting.

module.exports = {
  watchOptions: {
    ignored: /node_modules/,
    poll: true
  }
};
  • "webpack": "4.31.0",
  • "webpack-cli": "3.3.2",
  • "webpack-dev-server": "3.10.3"
  • WSL 2
  • Distributor ID: Ubuntu
  • Description: Ubuntu 18.04.5 LTS
  • Release: 18.04
  • Codename: bionic
    FYI webpack watch option
    https://webpack.js.org/configuration/watch/#watchoptionspoll
    However, but I still don't understand that I don't have to set this option when I use Windows.
    If someone can explain, I will appreciate it.
    Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests