Wrong baseURL (https://ntl.fyi/exit-code-255)

I’ve built my first Hugo website and everything works fine on the local Hugo server, both in development and production. I’ve tested the site locally with netlify dev and it runs fine. I’ve checked the log with netlify build and there aren’t errors.

However, when I try to upload the site to Netlify through GitHub I get these errors:


4:33:56 PM: ERROR 2023/01/30 16:33:56 render of “page” failed: execute of template failed: template: equipment/single.html:14:15: executing “main” at <partial “image-carousel” .>: error calling partial: execute of template failed: template: partials/image-carousel.html:12:11: executing “partials/image-carousel.html” at <partial “image” (dict “src” . “page” $ “alt” $.Title “format” “equipment”)>: error calling partial: “/opt/build/repo/layouts/partials/image.html:4:36”: execute of template failed: template: partials/image.html:4:36: executing “partials/image.html” at <.src>: wrong type for value; expected string; got *resources.resourceAdapter
4:33:56 PM: Error: Error building site: failed to render pages: render of “page” failed: “/opt/build/repo/layouts/projects/single.html:28:45”: execute of template failed: template: projects/single.html:28:45: executing “main” at : can’t evaluate field BaseName in type interface {}
4:33:56 PM: Error message
4:33:56 PM: Command failed with exit code 255: hugo --debug --minify --baseURL $DEPLOY_PRIME_URL (Search results for '"non-zero exit code: 255"' - Netlify Support Forums)
4:33:56 PM:
4:33:56 PM: Error location
4:33:56 PM: In build.command from netlify.toml:
4:33:56 PM: hugo --debug --minify --baseURL $DEPLOY_PRIME_URL
4:33:56 PM:
4:33:56 PM: Resolved config
4:33:56 PM: build:
4:33:56 PM: command: hugo --debug --minify --baseURL $DEPLOY_PRIME_URL
4:33:56 PM: commandOrigin: config
4:33:56 PM: environment:
4:33:56 PM: - NODE_ENV
4:33:56 PM: publish: /opt/build/repo/public
4:33:56 PM: publishOrigin: config


The question is why is this happening and how can I fix this?

The problem seems to be related to baseURL.

Removing “–baseURL $DEPLOY_PRIME_URL” allowed me to deploy the site with ‘netlify deploy’ from the cmd. And if I run ‘netlify deploy --prod’ I get this https://bullaki.netlify.app/.

This seems to suggest that the problem might be related to the baseURL, which in the Hugo config.yaml file is defined as

baseURL: 'https://bullaki.netlify.app/'

Now there are issues with some of the links:

So, I’m not sure where it’s picking up localhost:1313 from. In the Hugo ‘list’ template used to build bullaki.netlify.app/projects/ the URLs of each page in the list is defined as {{ .Permalink }}.

I would imagine a solution would be to ensure the baseURL in {{ .Permalink }} corresponds to the actual URL site on Netlify.

How can I do that? Is this likely to fix the issue?

Thanks! :slight_smile:

One more thing. I’ve stripped the Hugo site in a new GitHub branch (0.1.9) to dig more into this issue and I also noticed that Netlify also fails to evaluate BaseName in path.BaseName in here:

{{ range .Resources.ByType "image" }}
{{if eq (path.BaseName .) (path.BaseName $tempHeroImage)}}
   {{ partial "image" (dict "src" . "page" $page "alt" "X" "format" "equipment") }}   
{{end}}
{{end}}

and then fails to build:


9:40:04 PM: ERROR 2023/01/30 21:40:04 render of “page” failed: “/opt/build/repo/layouts/projects/single.html:28:45”: execute of template failed: template: projects/single.html:28:45: executing “main” at : can’t evaluate field BaseName in type interface {}


If I comment this section of the Hugo template the site deploys https://magical-kangaroo-b04b5a.netlify.app/.

It seems that by adding the Hugo version in the netlify.toml file:

[build]
  publish = "public/"
  command = "hugo --debug --minify"
[build.environment]  
  NODE_ENV = "production"
  HUGO_VERSION = "0.105.0"

I don’t get this error and it does evaluate path.BaseName without problems.

To be honest this is a really bizarre behaviour!

It seems that the solution to this problem was to:

  • remove --baseURL $DEPLOY_PRIME_URL and to specify the current Hugo version.
  • build and deploy the site with Neflify CLI (netlify build, netlify deploy, netlify deploy --prod)

This is the netlify.toml config file I’ve used:

[build]
  publish = "public/"
  command = "hugo --debug --minify"
[build.environment]  
  NODE_ENV = "production"
  HUGO_VERSION = "0.105.0"

As a result now all links seem to be fine, there’s no localhost appearing.

The GitHub route however still gives errors, it’s unclear why.

Great self solving.

I don’t use Hugo myself, but this section from the documentation makes me feel like HUGO_VERSION is basically required, as the longer it has been since the release of a build image the more out-of-date the default version of Hugo running on Netlify would be.

By default we’ll use the Hugo version that is preinstalled in your site’s initial build image. Because the preinstalled version may not match your local version, we recommend setting a HUGO_VERSION environment variable.

1 Like

Hi @SL654 thanks so much for coming back and sharing your solution!