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

Not detecting newly added files #282

Open
pensierinmusica opened this issue Jan 18, 2014 · 46 comments
Open

Not detecting newly added files #282

pensierinmusica opened this issue Jan 18, 2014 · 46 comments

Comments

@pensierinmusica
Copy link

If I understand correctly, grunt-contrib-watch should detect any added, modified, or deleted file that matches the patters specified in the Grunt configuration file.

On the other hand, I noticed that in my case it doesn't detect newly added files at all.
Here's an example of my Grunt configuration:

  grunt.initConfig({
    watch: {
      options: {
        livereload: true
      },
      styles: {
        files: ['<%= yeoman.app %>/styles/sections/*.styl'],
        tasks: ['stylus', 'autoprefixer'],
        options: {livereload: false}
      },
      iconfont: {
        files: ['<%= yeoman.app %>/images/icons/*.svg'],
        tasks: ['webfont', 'stylus'],
      }

grunt-contrib-watch perfectly detects modifications to existing files, but for example if I add a new .styl file in the specified folder nothing happens. I'm using Node 0.10.24 on OSX Mavericks.

Any advice on what might be causing the problem?

Thanks :)

@shama
Copy link
Member

shama commented Jan 19, 2014

Strange, I don't think it's because of the hyphens. I work with file names with hyphens in them on a daily basis without any issues. What node.js version? What OS and version? What are the actual file names? Are you sure they are matching? Try grunt watch --verbose.

@pensierinmusica
Copy link
Author

Hi @shama , thanks for the quick reply, I've checked and you're perfectly right: in fact the problem is not related to file names, but inability to detect newly added files (sorry for the confusion).

I've just updated the original issue here above with all details.

Do you have any advice on how to get the problem fixed?

Thanks! :)

@shama
Copy link
Member

shama commented Jan 21, 2014

What is the path of <%= yeoman.app %>?

Also, just a personal request, in the future would you mind adding a new comment or opening a new issue instead of editing your existing one? Just to avoid confusion with someone else coming across the same issue reading the thread. Thanks!

@pensierinmusica
Copy link
Author

Hi @shama, sure no worries I'll make sure to open new issues in the future :) In this case, after I understood the problem better I just realized the original issue was useless, and that's why I modified it.

Regarding your question, for this specific project where I have the problem, the path of <%= yeoman.app %> is ., or else the current directory. You can see a copy of the configuration here below:

var yeomanConfig = {
  app: '.',
  dist: 'dist'
};

Any thoughts? Thanks :)

@shama
Copy link
Member

shama commented Jan 21, 2014

Hmm that could be it. The cwd is always implied so a ./ never needs to be prepended. It could be related to this issue when ./ is prepended, it breaks some of the events: shama/gaze#66

@pensierinmusica
Copy link
Author

I see, thanks for pointing that out! Removing the <%= yeoman.app %> prefix (and consequently the .), together with the first / at the beginning of the path, fixed the problem :)

On the other hand, as a general approach I actually liked having a variable defined once in the yeomanConfig object, and then referred to elsewhere in the Grunt config file. This way, if one needs to change the folder structure or location at any point, the value has to be updated in one place only.

So, I still think it would be cool to be able to use . and have grunt-contrib-watch detect newly added files. Is there any chance that the bug could be fixed in Gaze, or does this make any sense to you at all?

Cheers!

@shama
Copy link
Member

shama commented Jan 21, 2014

Yep, it's fixed the next version of gaze. :) Which will land here as soon I as get safe writes solid for linux (last failing test on that branch).

@pensierinmusica
Copy link
Author

A-w-e-s-o-m-e!!

Thanks a lot, great job ;)

@spacenick
Copy link

Still experiencing that issue with no "." in my cwd; weird

@dannyfritz
Copy link

Had this problem and removing ./ from the beginning of my files options fixed it for me. 👍

@JSteunou
Copy link

JSteunou commented Jun 4, 2014

Still having this issue with things like files: ['src/**/*.hbs'] when adding a file in a new empty folder.

@shama Having the feeling this issue keeps rising from the dead. #166 What can we do to help you on this?

@sshmyg
Copy link

sshmyg commented Sep 22, 2014

+1

@spacenick
Copy link

Same than @JSteunou

@sshmyg
Copy link

sshmyg commented Sep 22, 2014

Is this plugin supported, yet?

@sshmyg
Copy link

sshmyg commented Sep 25, 2014

I found bug in my Gruntfile. Don't use './' before file path. Watcher doesn't work on file add, with this.

@romamatusevich
Copy link

Remove of './' works for new files of non-empty folders, but I have an issue when adding a files in a new empty folder.

@codezninja
Copy link

+1 I'm having the same issue on empty folders and newly created folders.

@foxx
Copy link

foxx commented Nov 6, 2014

Same problem here, nfi why

@isadovskiy
Copy link

The same problem is here. Adding new folder and then adding new file into does not detected by watch task (OS: Windows 7 x64).

@romamatusevich
Copy link

Recked on OS X 10.9.5. Works fine.

@FremyCompany
Copy link

I can confirm that "adding a new folder and then adding a new file into it is not detected by the watch task (OS: Windows 7 x64)". In my case, I'm adding the folder from a symbolic link, which may or may not explain the issue.

@Dreytac
Copy link

Dreytac commented Nov 25, 2014

In case it might help someone else, I had the same problem (OS: Windows 8.1 x64) until I set:

options: {
  event: ['changed', 'added', 'deleted']
}

After I set that under options it appears to fix my issue of not detecting new files / folders. Not sure why the default of event: 'all' didn't work.

@rotemdan
Copy link

I experienced the same problem when I had "./" at the beginning of the search path. I removed it and it now it does detect newly added files in non-empty directories. I can confirm that it still doesn't detect new files in an empty directory. Applying @denney's suggestion didn't seem to help. I also tried setting the cwd property in the options to the base search path and it didn't help.

(node 0.12, grunt: 0.4.5, grunt-contrib-watch: 0.6.1 on Windows 7 64bit)

As this issue has been unresolved for more than a year now (and more than year and a half for related ones such as #166 and shama/gaze#177 and shama/gaze#167). Being the most popular (and one of the most useful) grunt plugins I find it strange no solution has been found yet and considering either fixing it myself or looking for an alternative plugin.

Edit: After further searching I've found this pull request for a related test: shama/gaze#103 . It seems there is an alternative to gaze called https://github.com/shama/navelgazer that's in development and may not have this problem. It may eventually be used in grunt-watch. I will look further into it.

@dominikwilkowski
Copy link

👍

@UnknownHero
Copy link

@foxx
Copy link

foxx commented Apr 27, 2015

I think this may be related to Vagrant shared folders (due to lack of inotify?)

@tandrewnichols
Copy link

FWIW, this task also does not work for added (or deleted, I think) files if the file paths are absolute.

@roNn23
Copy link

roNn23 commented Jul 1, 2015

https://github.com/unbalanced/grunt-simple-watch
fixed the problem for me also!

@leedorian
Copy link

@UnknownHero It's works for me, this issue waste me 2 days, OMG.

@ezk84
Copy link

ezk84 commented Nov 11, 2015

Having the same issue where newly created less files aren't watched.

I've managed to reproduce this with a minimal example Gruntfile.js:

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-watch');

    var config = {
        watch: {
            less: {
                files: ['src/**/*.less'],
                tasks: ['listfiles:less']
            },
            js: {
                files: ['src/**/*.js'],
                tasks: ['listfiles:js']
            }
        },
        listfiles: {
            js: {
                src: ['src/**/*.js']
            },
            less: {
                src: ['src/**/*.less']
            }
        }
    };

    grunt.initConfig(config);

    grunt.registerMultiTask('listfiles', 'List files matched', function () {
        console.log(this.filesSrc);
    });
};

Now if we create a src/test.js and then launch grunt watch:

  • Creating a src/test2.js triggers the watch
  • Creating a src/test.less does not trigger the watch.

What seems to be happening is that the absence of at least one matching file in the directory prevents watch from triggering on subsequent changes in that directory (for a given pattern). This is why empty directories are completely ignored, but also non-empty directories that don't have any matching files.

Hope this can help bring about a solution.

@joskuijpers
Copy link

+1

4 similar comments
@benjaminfunk
Copy link

+1

@rockyromano
Copy link

+1

@mcela
Copy link

mcela commented Feb 16, 2016

+1

@toptalo
Copy link

toptalo commented Feb 19, 2016

👍

@gfpacheco
Copy link

gfpacheco commented Jun 22, 2016

More than 2 years and still no solution or explanation for this issue?

@joskuijpers
Copy link

Nope, still having this problem. I will try to debug myself tomorrow. It is a really annoying bug.

@feam-codes
Copy link

feam-codes commented Jul 6, 2016

It seems that there is only a problem with new files, if the watcher is configured to look at specific file types. I now use 'src/js/**' instead of 'src/js/**/*.js' and the watcher works as expected. The watcher is triggered after adding new files and after changing them without to restart the watch task. Only a little workaround with some restrictions but maybe helpful for debugging.

@dr0bz
Copy link

dr0bz commented Jul 13, 2016

I think this may be related to Vagrant shared folders (due to lack of inotify?)

@foxx in my case with vagrant and nfs it is really the problem with lack of inotify. https://github.com/unbalanced/grunt-simple-watch solves it through polling but it uses 20%-25% cpu of the guest machine instead of 5% with normal watch.

@dr0bz
Copy link

dr0bz commented Jul 13, 2016

grunt-simple-watch lacks livereload support :(

@Rybadour
Copy link

@seomantix I tried to remove the file extension and the "*" but it still doesn't work. Perhaps when you tested it you had an old file where you didn't expect?

makingmerry pushed a commit to makingmerry/grunt-php-site that referenced this issue Oct 27, 2016
- see thread:
gruntjs/grunt-contrib-watch#282
- implemented suggestion by user seomantix
- update to read me
@zachrybaker
Copy link

Still happening. OSX

@taburetkin
Copy link

still have this issue, win10.
and i have found that
if i have file pattern files:['tmpl/**/*.html']
and i have tmpl/folderA when watch started
now i want to create tmpl/folderB and tmpl/folderB/new.html

  1. creating folder tmpl/folderB
  2. creating new file in folder tmpl/folderB , just to be sure that watcher fails to rise event
  3. then creating any new file in tmpl/folderA (because it existed on watcher start and watcher will rise event which will fix something)
  4. and after that creating the tmpl/folderB/new.html. done. watcher will rise event.

i think something bad happens after new folder is created. )

@wrager
Copy link

wrager commented Oct 24, 2017

The issue also exists in this case (Windows_NT x64 10.0.14393):

// Formats are weird, because it actually was expressions with variables
styles: {
    // Adding files is detected
    files: [['lib/**/*.less']],
    tasks: ['...']
},
devInfo: {
    // Adding files is not detected
    files: [['lib/**/index.ts']],
    tasks: '...'
},
options: {
    spawn: false,
    event: ['changed', 'added', 'deleted']
}

@axten
Copy link

axten commented Nov 1, 2018

I can confirm that the bug still exists with 1.1.0.
It only occurs if this file type doesn't exist in this folder before adding.
When adding a second file watch works as expected.

Update: It seems that gaze is the cause: shama/gaze#177

@ve3
Copy link

ve3 commented Jun 11, 2019

grunt-cli v1.3.2
grunt v1.0.4
2019-06-12
problem still exists.

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

No branches or pull requests