Excluding a directory from Jekyll watch
Asked Answered
N

3

13

I'm using Jekyll 3.1.1 to generate a blog and I recently introduced a Git hook to automatically publish changes pre-push.

After introducing this hook, I have started getting the following error when I run jekyll serve:

Configuration file: /Users/egillespie/Projects/blog.givingjar.org/_config.yml
            Source: /Users/egillespie/Projects/blog.givingjar.org
       Destination: /Users/egillespie/Projects/blog.givingjar.org/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
                    done in 0.223 seconds.
        ** ERROR: directory is already being watched! **

        Directory: /Users/egillespie/Projects/blog.givingjar.org/node_modules/git-scripts/bin/hooks

        is already being watched through: /Users/egillespie/Projects/blog.givingjar.org/node_modules/git-scripts/bin/hooks

        MORE INFO: https://github.com/guard/listen/wiki/Duplicate-directory-errors
 Auto-regeneration: enabled for '/Users/egillespie/Projects/blog.givingjar.org'
Configuration file: /Users/egillespie/Projects/blog.givingjar.org/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

What's peculiar is that I am excluding node_modules in _config.yml:

exclude:
  - Gemfile
  - Gemfile.lock
  - LICENSE
  - README.md
  - package.json
  - Gruntfile.js
  - node_modules

node_modules is correctly being excluded from building (i.e. there is no node_modules subdirectory in _site).

I'm also excluding node_modules in .gitignore:

# project
node_modules
_site*
.sass-cache
.jekyll-metadata

# general
.DS_Store
Thumbs.db
ehthumbs.db

Based on this GitHub issue and this commit it seems like node_modules should be excluded from the watch, but it's not. I can't decipher from the documentation if there's another way to exclude files from the watch.

What is the proper way for me to exclude a directory from the watch and avoid the error described above?

Nevus answered 9/2, 2016 at 20:12 Comment(4)
Is your problem resolved ? If not, can you show more about the hook itself ?Pula
Did you ever solve this? I'm struggling with the same watch issue a year later...Celebrated
@RossR I was never able to resolve this issue. I migrated to Netlify so I would no longer need the Git hook, which worked around the scenario that caused this issue.Nevus
I asked a question on Jekyll Talk and it seems likely the problem is on my side. My guess: I have some symlinks, and Jekyll Watch imports the parent of a symlink (probably for efficiency). Anyway, I removed the symlinks and removed the problem.Celebrated
S
3

The value for exclude parameter in _config.yml should be an array i.e.

exclude: ['_site', 'node_modules', ...]

Source: Jekyll Documentation - Configuration

Stpierre answered 11/2, 2016 at 14:36 Comment(4)
The syntax I'm using is an alternative approach to creating an array in YAML. I did try it your way, though, and I still get the error. yaml.org/spec/1.2/spec.html#id2759963Nevus
I found this as a working fix. See if this works for you. https://mcmap.net/q/908368/-exclude-jekyll-directory-from-watch-but-not-buildStpierre
Thanks for pointing out this workaround, Jabran. Unfortunately, it doesn't get rid of the error in my case.Nevus
same issue, but this can not help.Sciuroid
F
2

Try this to your _config.yml:

keep_files: [node]

where node is a folder to exclude from the --watch. What this will do is keeping the folder node untouched by jekyll build. Then add all files that you want to keep in the site root but not rendered by Jekyll.

Forbiddance answered 11/2, 2016 at 19:34 Comment(7)
I added node_modules and I still get the error. The documentation suggests that keep_files tells Jekyll to leave files in _site alone. Unfortunately, node_modules is in the base of my project and Node does not offer a way to change that. I did try passing ../node_modules to keep_files to see if I could trick Jekyll, but that didn't work either.Nevus
Hmm... Try exclude: [node_modules, Gemfile, etc] and see how it goes... If doesn't work, and none of the answers here work, you can always try asking on Jekyll Talk.Forbiddance
I tried exclude: [node_modules, Gemfile, etc], also to no avail. I'll check out Jekyll Talk and report back. Thanks.Nevus
Try adding this line to the file.gitignore: node_modulesForbiddance
node_modules is already in my .gitignore file. Sorry for not providing that in my question.Nevus
wow. this is definitely odd then! Better try Jekyll Talk. Ask for @parkr - he is "the boss" there!Forbiddance
I posed the question on Jekyll Talk. *fingers crossed* Thanks for the referral!Nevus
A
2

Judging by the paths displayed in your output, you're on macOS. The jekyll-watch gem is responsible for this area (watch/rebuild features), which itself depends on the 'listen' gem. The listen gem itself uses the rb-inotify gem as a dependency, which has several issues with macOS specifically and its filesystem. This results in several bugs in regeneration behaviour that aren't not easy to fix. Background and relevant bugs:

You can try using the 'polling' method: https://github.com/guard/listen#listen-adapters instead, but it's much slower.

Aubyn answered 29/6, 2022 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.