Reputation: 1672
I tried running webpack --watch
and after editing my JS files, it doesn't trigger an auto-recompilation.
I've tried reinstalling webpack
using npm uninstall
but it's still not working.
Any ideas?
Upvotes: 126
Views: 110835
Reputation: 13381
FYI: it seems OS X can have a folder get corrupted and no longer send fsevents
(which watchpack
/chokidar
/Finder uses) for itself and any child folders. I can't be sure this is what happened to you, but it was very frustrating for me and a colleague.
We were able to rename the corrupt parent folder and then watch events immediately came through as expected. See this blog post for more info: http://livereload.com/troubleshooting/os-x-fsevents-bug-may-prevent-monitoring-of-certain-folders/
The recommended fixes from the above link are:
First two did not work for us, didn't try the Spotlight suggestion, and the re-creation did not prove necessary.
We were able to find the root problem folder by opening Finder and creating files in each successive parent folder until one showed up immediately (since Finder will get hosed by this bug as well). The root-most folder that does not update is the culprit. We just mv
'd it and mv
'd it back to its original name, and then the watcher worked.
No idea what causes the corruption, but I'm just glad to have a fix.
Upvotes: 92
Reputation: 697
Adding the following code to my webpack configuration file fixed the issue for me. Don't forget to ignore your node_modules folder, as that would kill performance for HMR (Hot Module Replacement):
watchOptions: {
poll: true,
ignored: /node_modules/
}
Upvotes: 57
Reputation: 294
Problem was in distiction between .js and .ts files. Why ?
On project build, Visual Studio compiles typescript files into .js and .js.map. This is totally unecessary, because webpack handles typescript files as well (with awesome-typescript-loader). When editing componet .tsx files in Visual Studio Code or With disabled compileOnSave option in tsconfig.json, edited ts file is not recompiled and my webpack was processing unactual .js file.
Solution was to disable compiling typescript files in visual studio on project build. Add
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
in PropertyGroup of your .csproj.
Upvotes: 0
Reputation: 645
It seems that the value of: max_user_watches
in the /proc/sys/fs/inotify/max_user_watches
is affecting webpack
To check your actual value
$cat /proc/sys/fs/inotify/max_user_watches
16384
16384 was in my case and it still wasnt enough.
I tried different type of solutions like:
$ echo fs.inotify.max_user_watches=100000 | sudo tee -a /etc/sysctl.conf
$ sudo sysctl -p
But it seems that even if I changed the value, when I restarted my PC it would go back to default one 16384.
Create the file:
sudo nano /etc/sysctl.d/90-override.conf
And populate it with:
fs.inotify.max_user_watches=200000
It seems 200000 is enough for me.
After you create the file and add the value, just restart the PC and you should be ok.
Upvotes: 2
Reputation: 1194
I met the same issue, tried many things, finally Chrome Clear Browsing Data on Mac worked for me.
These modules have been installed:
"browser-sync": "^2.26.7",
"browser-sync-webpack-plugin": "^2.2.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9"
Upvotes: 0
Reputation: 233
Folder case sensitivity was my issue. My code calls to require() had all lowercase path names BUT the actually directories had an uppercase letter in them. I renamed all my directories to lowercase and webpack watching worked instantly.
Upvotes: 18
Reputation: 465
I came across this question when I was having a similar issue-- it appeared that webpack was not rebundling, even when running webpack --config.
I even deleted bundle.js and the webpage was still displaying as before my edits.
For those of you who get this same problem, I finally did the 'empty cache and hard reload' option in chrome (right click the reload button with the devtools open) and that did that trick
Upvotes: 0
Reputation: 51
If this happened suddenly in your project, then this could fix the issue.
Maybe somehow the files which were tracking your project changes which webpack looks for got corrupted. You can create them again just by following simple steps.
Upvotes: 1
Reputation: 316
Also had this issue inside a VirtualBox (5.2.18) Ubuntu (18.04) VM using Vagrant (2.1.15) with rsync synchronization. Suddenly, first build runs great but Webpack does not take the changes into consideration afterwards, even with fs.inotify.max_user_watches=524288
set. Adding poll: true
in Webpack config didn't help either.
Only vagrant-notify-forwarder
worked (vagrant-fsnotify didn't, for some reason), but then the rebuild happened too quickly after saving the file on the host and I suppose that rsync didn't have enough time to finish its task (maybe due to the amount of synced directories inside my Vagrantfile?).
Finally I made the watch work again by also increasing the aggregateTimeout
in my Webpack config:
module.exports = {
watch: true,
watchOptions: {
aggregateTimeout: 10000
},
...
}
If this solution works for you, try lowering this value again, otherwise you'll have to wait 10 seconds until the build restarts each time you hit save. The default value is 300 ms.
Upvotes: 4
Reputation: 95
The thing is: webpack loads script from some weird url: webpack:/// which is cached.
You should add version at the end of your script to prevent caching:
main-compiled.js?v=<?php echo time()?>"
Upvotes: -1
Reputation: 41
For me, creating folders and files in VS Code was the issue. To fix, I re-cloned my repo and this time, created new folders and files through the command line instead of Code. I think Code was corrupting the files for some reason. I saw the application just updated so maybe it's a new bug.
Upvotes: 4
Reputation: 2806
I have had this problem when working with WebStorm.
Disabling Settings -> System Settings -> "safe write" resolved it for me.
Found the recommendation to do so in: WebPack Troubleshooting
Upvotes: 31
Reputation: 358
For me deleting node_modules
and doing npm install or yarn again to install all the packages solved the problem
Upvotes: 1
Reputation: 13106
It wasn't recompiling for me but then I realized / remembered that webpack watches the dependency graph and not just a folder (or files). Sure enough the files I was changing weren't part of that graph yet.
Upvotes: 6
Reputation: 331
I was having the same issue on a .vue file. When the server restarted all worked fine, but on the next save it didn't recompiled anymore. The issue was on the import file path that had one letter capitalized. It's very hard to figure this issue because everything works on a server reboot. Check the case of your paths.
Upvotes: 8
Reputation: 31
The way I resolved the issue was finding a capitalization error in an import path. Folder on file system had lower case first letter, import path was upper case. Everything compiled fine, so this was just a webpack watch include issue.
Upvotes: 3
Reputation: 355
I had similar issue, neither webpack or rollup in watch mode ware catching the changes I made. I found out that it was basically my fault as I was changing module (.tsx file) which wasn't yet imported anywhere in the application (for example App.ts which is entry point) and I was expecting build tools to report errors I made there.
Upvotes: 4
Reputation: 257
I have the same issue. And I notice it's not compiling because my folder contains some character(*). And using the old watcher plugin seems to resolve the issue. Add this line to your webpack config file.
plugins: [
new webpack.OldWatchingPlugin()
]
Upvotes: 2
Reputation: 3507
I am adding another answer because I believe that this is the best solution so far. I am using it every day and it rocks! Just install this library :
https://github.com/gajus/write-file-webpack-plugin
Description : Forces webpack-dev-server program to write bundle files to the file system.
How to install :
npm install write-file-webpack-plugin --save-dev
Upvotes: 0
Reputation: 111
Note that if you run webpack within a virtual machine (Vagrant / Virtualbox) and you change your files on the host platform, file updates in the shared folder may not trigger inotify on Ubuntu. That will cause the changes to not be picked up by webpack.
In my case, editing and saving the file on de guest (in vi) did trigger webpack. Editing it on the host (in PhpStorm, Notepad or any other application) dit NOT trigger webpack whatever I did.
I solved it by using vagrant-fsnotify.
Upvotes: 11
Reputation: 973
After trying a handful of strategies for fixing this problem I ended up just giving up but then while solving another issue I tried again and all of sudden the --watch
flag was finally working.
To be honest I do not know what specifically made it work but after performing the following steps it just started working:
1. Install most recent gcc version
$ sudo port install gcc48
$ sudo port select --set gcc mp-gcc48
2. Install most recent clang version
$ sudo port install clang-3.6
$ sudo port select --set clang mp-clang-3.6
3. Export variables holding the patch to C and C++ compiler
$ export CC=/opt/local/bin/clang
$ export CXX=/opt/local/bin/clang++
It might have happened that while installing these packages some dependency just added the missing piece of the puzzle, who knows ...
Hope this help anyone struggling out there to make it working.
Upvotes: 1
Reputation: 145
Possible solution: changing context to the app directory.
I had all my webpack config files in a sub folder:
components/
webpack/
development.js
app.js
In webpack/development.js
, set context: path.join(__dirname, '../')
solved my problem.
Upvotes: 1
Reputation: 3507
An easy solution on MacOS is the following :
Open two terminal windows in the same directory that your project resides.
In the first terminal window run : webpack --watch
In the second terminal windows run : webpack-dev-server
I have tried many possible solutions and this seems to be the most reliable
Upvotes: 1
Reputation: 113
If changing fs.inotify.max_user_watches as pointend out by César still doesn't work try to use polling instead of native watchers by creating your script as shown in the docs or running webpack with --watch --watch-poll
options.
Upvotes: 11
Reputation: 1790
If you are using Vim you should try setting backupcopy to yes rather than the default auto. Otherwise Vim will sometimes rename the original file and create a new one, which will mess up with webpack watch:
https://github.com/webpack/webpack/issues/781
Just add this to your vim settings if this is the case:
set backupcopy=yes
Upvotes: 7
Reputation: 2316
Just to add to possible solutions: I had my project folder inside a Dropbox folder, moving it out solved the problem for me. (OS X)
Upvotes: 16
Reputation: 1372
If your code isn't being recompiled, try increasing the number of watchers (in Ubuntu):
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Source: https://webpack.github.io/docs/troubleshooting.html
Upvotes: 93
Reputation: 857
One issue is that if your path names aren't absolute then things like this will happen. I had accidentally set resolve.root
to ./
instead of __dirname
and this caused me to waste a lot of time deleting and re-creating files like the guys above me.
Upvotes: 13