gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.05k stars 7.54k forks source link

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

Closed wangchucheng closed 2 years ago

wangchucheng commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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).

wangchucheng commented 2 years ago

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/....

tknx commented 2 years ago

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[bot] commented 2 years ago

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.