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

11ty.js templates not updating on --watch/serve (Windows, at least) #596

Closed
hdoro opened this issue Jul 4, 2019 · 13 comments
Closed

11ty.js templates not updating on --watch/serve (Windows, at least) #596

hdoro opened this issue Jul 4, 2019 · 13 comments
Labels
bug: windows Issue reported for the Windows environment bug
Milestone

Comments

@hdoro
Copy link

hdoro commented Jul 4, 2019

Describe the bug:

Templates written in Javascript are properly watched by Eleventy, but changes made to them don't propagate to resulting _site

To Reproduce

  1. Create an empty directory and include a simple index.11ty.js template there;
  2. Run eleventy --serve in the dir
  3. Make changes to index.11ty.js and see if they're reflected in the _site folder

Expected behavior

Say I were to change my layout from '<h1>Home here</h1>' to 'Home', I'd expect _site/index.html to become solely home.

Screenshots

I've actually recorded a video of this behavior here.

Environment:

  • OS and Version: Windows 10
  • Eleventy Version 0.8.3

Additional context

For now I've been simply eleventy building every time I make a change, but you can imagine how unproductive and upsetting this is... 😔 Oh, and the other templating languages are not an option for my current project.

@zachleat zachleat added bug bug: windows Issue reported for the Windows environment and removed needs-triage labels Jul 12, 2019
@zachleat
Copy link
Member

Great video and description, thanks!

I’m almost certain you found a bug.

I’d bet this has something to do with the pieces of our code that reset the Node require cache. I’m guessing there is a bug with how this is interpreted in Windows. If you want to start investigating (depending on your familiarity with Node) you can find them by searching the code-base for delete require.cache. If you want to add some console.logs there and see what outputs, that’d be helpful!

@hdoro
Copy link
Author

hdoro commented Jul 13, 2019

Alright, not sure I'm the best at the bugging, but here we go:

  1. I got into src/Engines/Javascript.js an went into the function initRequireCache, which has a line delete require.cache[requirePath]
  2. Then I added the following before the if statement: console.log(inputPath, requirePath, requirePath in require.cache)
  3. And got the following when I saved my minimal index.11ty.js file: ./index.11ty.js C:/desenvolvimento/tests/11ty-debug/index.11ty.js false
  4. And I tried re-running the process, but requirePath in require.cache is always false.

So apparently the cache is never deleted because it's never there, but that's as far as I understand from this haha

Any other debugging you'd like me to do?

I'm actually going to test this on Glitch.com to see how this behaves and then get back to you 😉

Edit: I've set-up a simple project on Glitch and there all works fine... I'm guessing they run everything on Linux, so this is probably a Windows bug... Oh, what an OS 😔

Edit 2: I now realize there are many delete require.cache in Eleventy's src, so not sure which one I should test for 🤔

@cschuller
Copy link
Contributor

cschuller commented Aug 25, 2019

The cache uses the real location of the module, to delete it, I recommend to resolve it first.

delete require.cache[require.resolve(fullModuleName)];

https://nodejs.org/api/modules.html#modules_require_resolve_request_options

Maybe I have time next week(end) to take a closer look, test it and provide a PR.

I am new to eleventy, but it will replace my own SSG😉

zachleat added a commit that referenced this issue Sep 5, 2019
@zachleat
Copy link
Member

Fixed by #683. This will go up with the next version

@FrankBeatrice
Copy link

FrankBeatrice commented Mar 30, 2021

Having a similar issue on Mac 03/30/2021
Not all changes showing up in the browser
Screen Shot 2021-03-30 at 4 33 18 PM
Screen Shot 2021-03-30 at 4 33 27 PM

@ShaneHudson
Copy link

I've also found that updating the layout does not always update the output, though it does always appear to trigger a rebuild with the old (cached?) layout. Rerunning the command manually makes it work. On Mac with Node v14.5.0

@simonsarris
Copy link

Same issue that ShaneHusdon is seeing I think, updating a template in _includes/ will rebuild but use the old version of the template. On Windows with 0.11.1 and node v12.18.3.

@ShaneHudson
Copy link

@zachleat As this issue is closed already, just want to check you have seen these newer comments? Should it new opened as a new issue? It is still occurring for me.

@antoniaat
Copy link

Also having the same issue on Mac. @ShaneHudson Which command are you rerunning manually to make it work?

@ShaneHudson
Copy link

@antoniaat I was just re-running the watch command, not ideal but worked.

@simonsarris
Copy link

@antoniaat and @ShaneHudson: I noticed this problem (updating templates does not live update the pages using them) happened only when using the plugin "html-minifier". Are you using it?

When I stopped using that plugin, the live reload issue went away. So it is possible that your issue is not eleventy's fault but some plugin (this one or another one) referenced in the eleventy config.

@ShaneHudson
Copy link

I've not touched the project I was having the issue on for a while, so cannot be sure... but think I had no plugins.

@starikcetin
Copy link

I've also found that updating the layout does not always update the output, though it does always appear to trigger a rebuild with the old (cached?) layout. Rerunning the command manually makes it work. On Mac with Node v14.5.0

I am experiencing the same issue using Pug templates. Windows 10, Node 18.17.1. Watch sees the change and compiles things, but I see the old version in the browser.

Something rather interesting is that using another program to host the dist folder (I am using Live Server plugin of VSCode) works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: windows Issue reported for the Windows environment bug
Projects
None yet
Development

No branches or pull requests

8 participants