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

Hugo can not find resource cache when setting a path in baseURL #9787

Closed
wangchucheng opened this issue Apr 15, 2022 · 7 comments · Fixed by #9942
Closed

Hugo can not find resource cache when setting a path in baseURL #9787

wangchucheng opened this issue Apr 15, 2022 · 7 comments · Fixed by #9942

Comments

@wangchucheng
Copy link

wangchucheng commented Apr 15, 2022

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.97.0+extended darwin/arm64 BuildDate=unknown

Does this issue reproduce with the latest release?

This is an issue for any theme which has a resource cache, especially those generated by PostCSS.

To reproduce it, you can use https://github.com/wangchucheng/hugo-eureka-starters as an example site and set baseURL = example.com/test. To force Hugo to look for cache instead of regenerating it, I set useResourceCacheWhen = always. The theme works well without baseURL or without resource cache.

There will be an error message like: Error: Error building site: POSTCSS: failed to transform "css/eureka.css" (text/css): resource "css/test/css/eureka.css_5423b02c25971c3328ec4f49ccfb7444" not found in file cache when running hugo or hugo server.

Hugo tends to find resource cache in css/<base-path>/.... However, the resource cache was in css/.... It is not possible for theme creators to know what path a user will use, so it looks like this may be a bug.

@tknx
Copy link

tknx commented May 17, 2022

I am having this problem all of a sudden too.

I can build locally, but I get a failed file cache error when I push to github for the action.

@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@bep bep self-assigned this May 27, 2022
@bep
Copy link
Member

bep commented May 27, 2022

To reproduce it, you can use https://github.com/wangchucheng/hugo-eureka-starters

I get the above failure in that starter even with a regular baseURL, which doesn't make a good test case.

@wangchucheng
Copy link
Author

wangchucheng commented May 27, 2022

To reproduce it, you can use https://github.com/wangchucheng/hugo-eureka-starters

I get the above failure in that starter even with a regular baseURL, which doesn't make a good test case.

Hi bep,

Thanks for your response! I got some feedback that this starter was not working with basic URL after Hugo 0.99.0, I have not looked into that (will do that soon) but this may not be the same reason as the one that has path in baseURL since the latter did not work even before Hugo 0.99.0. This starter can work with Hugo 0.97.0 at least as my CI uses this version.

Update: this starter can work with Hugo 0.99.0 now with a regular baseURL, but not with basicURL with path.

@bep
Copy link
Member

bep commented May 27, 2022

I got some feedback that this starter was not working with basic URL after Hugo 0.99.0,

OK, now I see it.

We added a new option to PostCSS in that release. In "all" the other transformers, I think I use the input options from the user as a base to create the cache key, which makes it more stable (it doesn't change if we add/remove options).

In your case it means that you need to repopulate the cache with the new version, but as I'm going to make this more stable going forward, it will also mean that the hash will also change in the next version of Hugo.

Also, there may be an issue with baseURL paths (which I suspect is part of the cache key, but shouldn't need to be).

bep added a commit to bep/hugo that referenced this issue May 27, 2022
By using the input map as the basis, which means the hash will not change if we add/rename/remove options.

This happened in Hugo 0.99, as we added a new options. This is unortunate.

Unfortunately this means that the cache keys for PostCSS will change one more time in 0.100, but will be stable going forward.

Note that we have implemented this pattern in all the other resource transformers.

Updates gohugoio#9787
@wangchucheng
Copy link
Author

wangchucheng commented May 27, 2022

Thanks, bep!

In your case it means that you need to repopulate the cache with the new version

Yes, it works great with regular baseURL after I updated the cache. It seems that I will do this again after Hugo 0.100 releases.

And FYI, the cache is still not working if baseURL contains path after the repopulation. Hugo still tries to find cache in css/<base-path>/... while the cache was in css/....

bep added a commit to bep/hugo that referenced this issue May 27, 2022
As that prevents Hugo projects with sub paths in their `baseURL` to use themes with cached resources.

Fixes gohugoio#9787
bep added a commit to bep/hugo that referenced this issue May 27, 2022
As that prevents Hugo projects with sub paths in their `baseURL` to use themes with cached resources.

Fixes gohugoio#9787
bep added a commit that referenced this issue May 27, 2022
By using the input map as the basis, which means the hash will not change if we add/rename/remove options.

This happened in Hugo 0.99, as we added a new options. This is unortunate.

Unfortunately this means that the cache keys for PostCSS will change one more time in 0.100, but will be stable going forward.

Note that we have implemented this pattern in all the other resource transformers.

Updates #9787
@bep bep closed this as completed in #9942 May 27, 2022
bep added a commit that referenced this issue May 27, 2022
As that prevents Hugo projects with sub paths in their `baseURL` to use themes with cached resources.

Fixes #9787
@tknx
Copy link

tknx commented May 27, 2022

OK, so I am clueless here... I ran a hugo mod get -u

My config.yaml has this:

baseURL: https://thethousandkingdoms.com/

When I run hugo server -D, I get the following:

> hugo server -D
Start building sites …
hugo v0.89.3-C88CDB56+extended windows/amd64 BuildDate=2021-11-15T12:17:46Z VendorInfo=gohugoio
Error: Error building site: POSTCSS: failed to transform "css/eureka.css" (text/css): Error: Failed to find 'assets/css/site'
  in [
    C:\Users\tarun\ttk,
        C:\Users\tarun\OneDrive\Desktop\thethousandkingdoms\_vendor\wangchucheng.com\hugo-eureka
  ]
    at C:\Users\tarun\OneDrive\Desktop\thethousandkingdoms\node_modules\postcss-import\lib\resolve-id.js:35:13
    at async LazyResult.runAsync (C:\Users\tarun\OneDrive\Desktop\thethousandkingdoms\node_modules\postcss\lib\lazy-result.js:396:11)
    at async Promise.all (index 0)
Built in 1195 ms

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants