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

Directory is already being watched #1990

Closed
cyrusstoller opened this issue Mar 8, 2019 · 16 comments
Closed

Directory is already being watched #1990

cyrusstoller opened this issue Mar 8, 2019 · 16 comments

Comments

@cyrusstoller
Copy link

This is a fantastic project. I really appreciate being able to develop using Vue and Rails in the same project.

I'm in the process of upgrading to 4.x. I followed the guide and things appear to be functioning properly. However, I'm running into an "error" when using Guard to run my tests and when opening a new rails console.

In my terminal that's running my tests I see the following a few times:

        ** ERROR: directory is already being watched! **

And then I also see it if I open a new rails console.

What's strange to me is that it doesn't really seem to be causing any errors. I'm still able to interact with my project. The node_modules that it calls out are:

  • mini-css-extract-plugin
  • compression-webpack-plugin

This is more of a minor annoyance than anything else. What's odd is if I close the rails console and then open a new rails console the errors don't appear. I'm assuming this has something to do with me using the default spring settings.

I'm not sure what will be most helpful for me to provide to help debug.

Here are some basics:

  • Rails v5.2.2
  • Ruby v2.5.3
  • Webpacker v4.0.2
  • Listen v3.1.5

Any tips for how to resolve these?

@jits
Copy link

jits commented Mar 9, 2019

@cyrusstoller – if you look further down in the error message you should see a link to https://github.com/guard/listen/wiki/Duplicate-directory-errors, which explains why the error occurs.

For now, I've gone with adding the following to config/spring.rb, to suppress the error:

# Listen >=2.8 patch to silence duplicate directory errors. USE AT YOUR OWN RISK
require 'listen/record/symlink_detector'
module Listen
  class Record
    class SymlinkDetector
      def _fail(_, _)
        raise Error, "Don't watch locally-symlinked directory twice"
      end
    end
  end
end

… which is a suggestion from the link mentioned above, but not recommended.

@cyrusstoller
Copy link
Author

Thanks for sharing. I don't feel great about using that solution. Are there other ways to approach this?

@jits
Copy link

jits commented Mar 13, 2019

@cyrusstoller – agreed, this is less than ideal. Unfortunately I didn't come across any other solutions in my (admittedly limited) investigations.

The link from the guard wiki above suggests that this has something to do with symlinks. But I'm not quite sure why there would be a symlink within a node module (I've possibly hit a limit in my understanding/knowledge here); my hunch is there's a deeper problem/bug at play here.

@jits
Copy link

jits commented Mar 13, 2019

Looking at the errors closely, I see:

Directory: /Users/jits/Projects/…/node_modules/.bin/compression-webpack-plugin

        is already being watched through: /Users/jits/…/patch-list/node_modules/compression-webpack-plugin
Directory: /Users/jits/Projects/…/node_modules/.bin/mini-css-extract-plugin

        is already being watched through: /Users/jits/…/node_modules/mini-css-extract-plugin

… looks like it's mistaking the executables within the .bin directories of node modules for directories – very likely a bug in listen.

@cyrusstoller – are you seeing this too when you get the error?

Will try to find time later to investigate further and file a bug report.

@cyrusstoller
Copy link
Author

I'm seeing the same thing. Any tips on how I can help investigate?

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Mar 13, 2019

image

I would exempt node_modules from being watched. Even if it eventually works, you are wasting perf & memory watching something that shouldn't be changing.

@cyrusstoller
Copy link
Author

Makes sense. I don't think I'm currently watching the node_modules from guard. I'll look for other places.

Here's my Guardfile:

guard :minitest, spring: "bin/rails test" do
  notification :terminal_notifier,
    activate: 'com.googlecode.iTerm2' if `uname` =~ /Darwin/

  # Rails 4+
  watch(%r{^app/(.+)\.rb$})                               { |m| "test/#{m[1]}_test.rb" }
  watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
  watch(%r{^app/controllers/(.+)_controller\.rb$})        { |m| "test/integration/#{m[1]}_test.rb" }
  watch(%r{^app/views/(.+)_mailer/.+})                    { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
  watch(%r{^lib/(.+)\.rb$})                               { |m| "test/lib/#{m[1]}_test.rb" }
  watch(%r{^test/.+_test\.rb$})
  watch(%r{^test/test_helper\.rb$}) { 'test' }
end

@jits
Copy link

jits commented Mar 15, 2019

@jakeNiemiec

I would exempt node_modules from being watched. […]

This would be ideal! I don't think there's a way to do this in Rails apps?

@jakeNiemiec
Copy link
Member

I don't think there's a way to do this in Rails apps?

@jits I changed my stack to let node do all the watching/proxying/reloading with https://github.com/Va1/browser-sync-webpack-plugin

It also excludes node_modules by default: https://www.browsersync.io/docs/options/#option-watch

@cyrusstoller
Copy link
Author

This seems like it might be related: rails/rails#32700

@jits
Copy link

jits commented Apr 14, 2019

There may be a fix for this (if you're using factory_bot):

https://github.com/thoughtbot/factory_bot_rails/releases/tag/v5.0.2

y-yagi added a commit to y-yagi/rails that referenced this issue Jun 2, 2019
`spring-watcher-listen` watch application root by default.
https://github.com/jonleighton/spring-watcher-listen/blob/c4bfe15805867e229588e4b776a7b87438137094/lib/spring/watcher/listen.rb#L58

This is necessary to watch the file (e.g. `.ruby-version`) in the
application root.

By this `node_modules` also be watched, and it is a possibility to be
shown a warning by `listen`.
Related to rails#32700, rails#34912, rails/webpacker#1990.

`listen` watches directory recursive by default, and it cannot avoid it.
guard/listen#111

So If this warning happens, the only workaround the user can do is remove
the gem.

The issue is likely to occur more frequently in Rails 6 because
`rails new` runs `webpacker:install` by default. Because of such a
state, I think that we should not recommend to use
`spring-watcher-listen`.

Spring has polling watcher, restart process works without this
`spring-watcher-listen`.
Because of polling base, CPU load may be higher than listen base. Still
I think that it is better than the warning comes out.
@guillaumebriday
Copy link
Member

Can this issue be closed ?

@cyrusstoller
Copy link
Author

I think so. I'm no longer experiencing this issue anymore using the latest versions of Rails.

@guillaumebriday
Copy link
Member

Feel free to close it then 👍

@gauravtiwari
Copy link
Member

Thanks @guillaumebriday for reviewing issues 🍰

@ColinDKelley
Copy link

For anyone following this thread, guard and listen warnings are now configurable as of listen v3.9.0.

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

6 participants