Can only run Hugo with --renderToMemory otherwise gets permission denied errors even after chmod a+rwx

Similar issue as Upgrading to Go1.22.1 & Hugo 0.124.1 causes multiple errors but I didn’t see a real solution to my issue discussed there.

In short, I can only run hugo --renderToMemory server. Running hugo or hugo server fails due to permission denied errors.

My machine:

uname -a
Darwin LAPTOP2.lan 18.7.0 Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64

Hugo version: 0.125.0

hugo version
hugo v0.125.0-a32400b5f4e704daf7de19f44584baf77a4501ab+extended darwin/amd64 BuildDate=2024-04-16T15:04:41Z VendorInfo=gohugoio

Hugo configuration

cat hugo.toml 
baseURL = 'https://example.org/'
languageCode = 'en-us'
title = 'My New Hugo Site'

[module]
 [[module.imports]]
 path = "github.com/McShelby/hugo-theme-relearn"

This works fine:

hugo --renderToMemory server

This does not work:

hugo server    
Watching for changes in /Users/it-user/tmp/introduktion-till-datorer.github.io/{archetypes,assets,content,data,i18n,layouts,static}
Watching for config changes in /Users/it-user/tmp/introduktion-till-datorer.github.io/hugo.toml, /Users/it-user/tmp/introduktion-till-datorer.github.io/go.mod
Start building sites … 
hugo v0.125.0-a32400b5f4e704daf7de19f44584baf77a4501ab+extended darwin/amd64 BuildDate=2024-04-16T15:04:41Z VendorInfo=gohugoio

ERROR Failed to publish Resource: open /Users/it-user/tmp/introduktion-till-datorer.github.io/public/css/theme-relearn-light.css: permission denied
ERROR Failed to publish Resource: open /Users/it-user/tmp/introduktion-till-datorer.github.io/public/css/theme-relearn-dark.css: permission denied
Built in 322 ms
Error: error building site: logged 2 error(s)

These are the permissions of the public and public/css directories.

tree -D -L 2 -puifd | grep public
[drwxr-xr-x it-user  Apr 17 16:22]  ./public
[drwxr-xr-x it-user  Apr 17 16:18]  ./public/categories
[drwxr-xr-x it-user  Apr 17 14:31]  ./public/css
[drwxr-xr-x it-user  Apr 17 14:31]  ./public/fonts
[drwxr-xr-x it-user  Apr 17 14:31]  ./public/js
[drwxr-xr-x it-user  Apr 17 16:18]  ./public/tags
[drwxr-xr-x it-user  Apr 17 14:31]  ./public/webfonts

Changing the permissions:

chmod -R a+w public
tree -D -L 2 -puifd | grep public
[drwxrwxrwx it-user  Apr 17 16:22]  ./public
[drwxrwxrwx it-user  Apr 17 16:18]  ./public/categories
[drwxrwxrwx it-user  Apr 17 14:31]  ./public/css
[drwxrwxrwx it-user  Apr 17 14:31]  ./public/fonts
[drwxrwxrwx it-user  Apr 17 14:31]  ./public/js
[drwxrwxrwx it-user  Apr 17 16:18]  ./public/tags
[drwxrwxrwx it-user  Apr 17 14:31]  ./public/webfonts 
cd public/css
chmod a+rwx theme-relearn*
ls -l | grep theme-relearn
-rwxrwxrwx  1 it-user  staff   3580 Apr 17 14:31 theme-relearn-bright.css
-rwxrwxrwx  1 it-user  staff   3349 Apr 17 14:31 theme-relearn-dark.css
-rwxrwxrwx  1 it-user  staff   3241 Apr 17 14:31 theme-relearn-light.css
-rwxrwxrwx  1 it-user  staff    136 Apr 17 14:31 theme-relearn.css

Running hugo again still fails with the same errors.

 cd ..
 cd ..
hugo
Start building sites … 
hugo v0.125.0-a32400b5f4e704daf7de19f44584baf77a4501ab+extended darwin/amd64 BuildDate=2024-04-16T15:04:41Z VendorInfo=gohugoio

ERROR Failed to publish Resource: open /Users/it-user/tmp/introduktion-till-datorer.github.io/public/css/theme-relearn-light.css: permission denied
ERROR Failed to publish Resource: open /Users/it-user/tmp/introduktion-till-datorer.github.io/public/css/theme-relearn-dark.css: permission denied
Total in 1417 ms
Error: error building site: logged 2 error(s)

I would like to understand why I get these errors and what to do to get rid of them.

The error points to this directory. What are its permissions?

These where the permissions of the /Users/it-user/tmp/ directory:

drwxr-xr-x   34 it-user  staff     1088 Apr 17 15:28 tmp

After changing to:

drwxrwxrwx   34 it-user  staff     1088 Apr 17 15:28 tmp

, I still get the same errors:

hugo
Start building sites … 
hugo v0.125.0-a32400b5f4e704daf7de19f44584baf77a4501ab+extended darwin/amd64 BuildDate=2024-04-16T15:04:41Z VendorInfo=gohugoio

ERROR Failed to publish Resource: open /Users/it-user/tmp/introduktion-till-datorer.github.io/public/css/theme-relearn-light.css: permission denied
ERROR Failed to publish Resource: open /Users/it-user/tmp/introduktion-till-datorer.github.io/public/css/theme-relearn-dark.css: permission denied
Total in 225 ms
Error: error building site: logged 2 error(s)
```

Quick test. CD into your tmp directory then run:

hugo new theme foo --themesDir .
cd foo
hugo server

The first command may look a little strange, but it’s great for quickly creating a populated test site.

This works!

So, the issue seems to be related to the Relearn theme?

OK, now add this to the test site config, and rename the layouts directory. Then test again. This should tell us if perms on the module cache are involved.

[module]
 [[module.imports]]
 path = "github.com/McShelby/hugo-theme-relearn"

I forgot a step in the above.

  1. hugo mod init foo in the root of the test site.
  2. Change the config per my previous reply.
  3. Rename the layouts directory.
  4. Build the site.

I figured out 1 and 2 by myself after a while :slight_smile:

I still get these errors:

hugo server
Watching for changes in /Users/it-user/tmp/foo/{archetypes,assets,content,data,i18n,layouts,static}
Watching for config changes in /Users/it-user/tmp/foo/hugo.toml, /Users/it-user/tmp/foo/go.mod
Start building sites … 
hugo v0.125.0-a32400b5f4e704daf7de19f44584baf77a4501ab+extended darwin/amd64 BuildDate=2024-04-16T15:04:41Z VendorInfo=gohugoio

ERROR Failed to publish Resource: open /Users/it-user/tmp/foo/public/css/theme-relearn-light.css: permission denied
ERROR Failed to publish Resource: open /Users/it-user/tmp/foo/public/css/theme-relearn-dark.css: permission denied
Built in 398 ms
Error: error building site: logged 2 error(s)

What do you mean with 3, rename the layouts directory? Why is this needed? Rename to what?

Renaming is not relevant to the test, but if the test passed, the rendered site would look weird/wrong because the layouts directory in the root of the test site would override some of the theme files. So, renaming it to anything is just a way to make sure it’s not overriding the theme.

Your issue is related to the theme. There’s a closed issue that may be related:
https://github.com/McShelby/hugo-theme-relearn/issues/734

I’d log an issue with the theme author. Please post the link here and I will provide a minimal reproducible example for the theme author.

cc: @McShelby

And here’s a failing minimal example:

git clone --single-branch -b hugo-forum-topic-49335 https://github.com/jmooring/hugo-testing hugo-forum-topic-49335
cd hugo-forum-topic-49335
hugo server

ERROR Failed to publish Resource: open /home/jmooring/code/hugo-testing/public/css/theme-relearn-light.css: permission denied
ERROR Failed to publish Resource: open /home/jmooring/code/hugo-testing/public/css/theme-relearn-dark.css: permission denied

If I vendor the module it works fine:

hugo mod vendor
hugo

This is just a clue as to what the problem might be. I am not recommending that you do this. You’d have to undo it to update the theme in the future (though undoing it just a matter of deleting the _vendor directory in the root of the project).

1 Like

I’ve added the following issue in the Relearn repo:

2 Likes

Thank you so much @jmooring for helping out.

1 Like

This will be fixed in the next theme release.

1 Like