Netlify build failing with module mount

Everything on a local machine building well for this Hugo site - everything on latest versions, but Netlify deployment fails which I can’t work out. Any insight would be good please for the part:

<resources.Concat>: error calling Concat: slice []interface {} not supported in concat

In context:

8:30:19 PM: ERROR 2021/02/10 20:30:19 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat

The issue is with Hugo Module Mounts, the single.html reference is just the point of failure.

in config.toml:

[[module.mounts]]
source = "node_modules/macy/dist/macy.js"
target = "assets/js/macy.js"

the source is present in the repo, but I’m wondering if having node_modules at root is the issue as I have another build which is pretty identical, but it runs inside a /theme folder. I’m mounting everything as per docs as a module and not using a theme here.

If macy.js is placed manually in assets/js and the config.toml mount removed… Netlify build works.

In baseof.html calling these looks like this:

{{ $macyjs := resources.Get "js/macy.js" }}
{{ $macyjsconfig := resources.Get "js/macy.config.js" }}
{{ $concatalljs := slice $menuconfig $macyjs $macyjsconfig | resources.Concat "js/bundle-all.js" | resources.Minify }}
{{ $secureallJS := $concatalljs | resources.Fingerprint "sha512" }}

Hey! Is the source code for your site publicly available somewhere? That would make it a lot easier to help, because we can try modifying things and seeing what works.

In the absence of that, my first guess here would be – are you sure that the version of Hugo in use on Netlify is identical to the version running on your machine? From memory, the Hugo on Netlify defaults to a really old version. You might need to set the HUGO_VERSION and HUGO_ENV variables, e.g.

[context.production.environment]
HUGO_VERSION = "0.80.0"
HUGO_ENV = "production"

[context.deploy-preview.environment]
HUGO_VERSION = "0.80.0"
HUGO_ENV = "production"

Thanks, yes - this is all in. Have made rep public here https://github.com/claysondesign/ccc-v5-hugo-tailwind. Have also tried with and without --gc and --minify flags - nothing.

Fuller error message:

7:26:57 AM: $ hugo --gc --minify
7:26:57 AM: Start building sites …
7:26:58 AM: ERROR 2021/02/14 07:26:58 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/storylayout.html:29:70: executing “_default/storylayout.html” at <resources.Concat>: error calling Concat: slice interface {} not supported in concat
7:26:58 AM: ERROR 2021/02/14 07:26:58 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice interface {} not supported in concat
7:26:58 AM: ERROR 2021/02/14 07:26:58 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice interface {} not supported in concat
7:26:58 AM: ERROR 2021/02/14 07:26:58 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice interface {} not supported in concat
7:26:58 AM: Total in 918 ms
7:26:58 AM: Error: Error building site: failed to render pages: render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice interface {} not supported in concat
7:26:58 AM: ​
7:26:58 AM: ────────────────────────────────────────────────────────────────
7:26:58 AM: “build.command” failed
7:26:58 AM: ────────────────────────────────────────────────────────────────
7:26:58 AM: ​
7:26:58 AM: Error message
7:26:58 AM: Command failed with exit code 255: hugo --gc --minify
7:26:58 AM: ​
7:26:58 AM: Error location
7:26:58 AM: In build.command from netlify.toml:
7:26:58 AM: hugo --gc --minify
7:26:58 AM: ​
7:26:58 AM: Resolved config
7:26:58 AM: build:
7:26:58 AM: command: hugo --gc --minify
7:26:58 AM: commandOrigin: config
7:26:58 AM: environment:
7:26:58 AM: - HUGO_VERSION
7:26:58 AM: - HUGO_ENV
7:26:58 AM: publish: /opt/build/repo/public
7:26:58 AM: headers:
7:26:58 AM: - for: /*
values:
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Caching artifacts

Did you try “delete cache and retry deploy”? Sometimes Hugo does not immediately look for new modules. Please post the FULL log of your netlify deploy (you can hide it from messing up your message like the following code)

[details="Summary"]
This text will be hidden
[/details]

Yes - Tried Clearing cache etc as well.

Summary

9:16:44 AM: Build ready to start
9:16:46 AM: build-image version: d84c79427e8f83c1ba17bcdd7b3fe38059376b68
9:16:46 AM: build-image tag: v3.6.1
9:16:46 AM: buildbot version: 29790781696345269c532deefac261952f54866d
9:16:46 AM: Building without cache
9:16:46 AM: Starting to prepare the repo for build
9:16:46 AM: No cached dependencies found. Cloning fresh repo
9:16:46 AM: git clone GitHub - claysondesign/ccc-v5-hugo-tailwind
9:17:53 AM: Preparing Git Reference refs/heads/master
9:17:57 AM: Starting build script
9:17:57 AM: Installing dependencies
9:17:57 AM: Python version set to 2.7
9:17:58 AM: v12.18.0 is already installed.
9:17:59 AM: Now using node v12.18.0 (npm v6.14.4)
9:17:59 AM: Started restoring cached build plugins
9:17:59 AM: Finished restoring cached build plugins
9:18:00 AM: Attempting ruby version 2.7.1, read from environment
9:18:01 AM: Using ruby version 2.7.1
9:18:02 AM: Using PHP version 5.6
9:18:02 AM: Started restoring cached node modules
9:18:02 AM: Finished restoring cached node modules
9:18:02 AM: Installing NPM modules using NPM version 6.14.4
9:18:03 AM: npm notice created a lockfile as package-lock.json. You should commit this file.
9:18:03 AM: npm WARN Invalid version: “5.0”
9:18:03 AM: npm WARN repo No description
9:18:03 AM: npm WARN repo No repository field.
9:18:03 AM: npm WARN repo No README data
9:18:03 AM: npm WARN repo No license field.
9:18:04 AM: up to date in 0.283s
9:18:04 AM: found 0 vulnerabilities
9:18:04 AM: NPM modules installed
9:18:04 AM: Installing Hugo 0.80.0
9:18:05 AM: Hugo Static Site Generator v0.80.0-792EF0F4/extended linux/amd64 BuildDate: 2020-12-31T13:46:18Z
9:18:05 AM: Started restoring cached go cache
9:18:05 AM: Finished restoring cached go cache
9:18:05 AM: go version go1.14.4 linux/amd64
9:18:05 AM: go version go1.14.4 linux/amd64
9:18:05 AM: Installing missing commands
9:18:05 AM: Verify run directory
9:18:08 AM: ​
9:18:08 AM: ────────────────────────────────────────────────────────────────
9:18:08 AM: Netlify Build
9:18:08 AM: ────────────────────────────────────────────────────────────────
9:18:08 AM: ​
9:18:08 AM: ❯ Version
9:18:08 AM: @netlify/build 9.1.2
9:18:08 AM: ​
9:18:08 AM: ❯ Flags
9:18:08 AM: deployId: 6028ea7c24ed4ffa117b5e82
9:18:08 AM: mode: buildbot
9:18:08 AM: ​
9:18:08 AM: ❯ Current directory
9:18:08 AM: /opt/build/repo
9:18:08 AM: ​
9:18:08 AM: ❯ Config file
9:18:08 AM: /opt/build/repo/netlify.toml
9:18:08 AM: ​
9:18:08 AM: ❯ Context
9:18:08 AM: production
9:18:08 AM: ​
9:18:08 AM: ────────────────────────────────────────────────────────────────
9:18:08 AM: 1. build.command from netlify.toml
9:18:08 AM: ────────────────────────────────────────────────────────────────
9:18:08 AM: ​
9:18:08 AM: $ hugo --gc --minify
9:18:08 AM: Start building sites …
9:18:09 AM: ERROR 2021/02/14 09:18:09 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/storylayout.html:29:70: executing “_default/storylayout.html” at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
9:18:09 AM: ERROR 2021/02/14 09:18:09 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
9:18:09 AM: ERROR 2021/02/14 09:18:09 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
9:18:09 AM: ERROR 2021/02/14 09:18:09 render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
9:18:09 AM: Total in 929 ms
9:18:09 AM: Error: Error building site: failed to render pages: render of “page” failed: “/opt/build/repo/layouts/_default/baseof.html:29:70”: execute of template failed: template: _default/single.html:29:70: executing “_default/single.html” at <resources.Concat>: error calling Concat: slice []interface {} not supported in concat
9:18:09 AM: ​
9:18:09 AM: ────────────────────────────────────────────────────────────────
9:18:09 AM: “build.command” failed
9:18:09 AM: ────────────────────────────────────────────────────────────────
9:18:09 AM: ​
9:18:09 AM: Error message
9:18:09 AM: Command failed with exit code 255: hugo --gc --minify
9:18:09 AM: ​
9:18:09 AM: Error location
9:18:09 AM: In build.command from netlify.toml:
9:18:09 AM: hugo --gc --minify
9:18:09 AM: ​
9:18:09 AM: Resolved config
9:18:09 AM: build:
9:18:09 AM: command: hugo --gc --minify
9:18:09 AM: commandOrigin: config
9:18:09 AM: environment:
9:18:09 AM: - HUGO_VERSION
9:18:09 AM: - HUGO_ENV
9:18:09 AM: - HUGO_ENABLEGITINFO
9:18:09 AM: publish: /opt/build/repo/public
9:18:09 AM: headers:
9:18:09 AM: - for: /*
values:
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
Caching artifacts
9:18:09 AM: Started saving node modules
9:18:09 AM: Finished saving node modules
9:18:09 AM: Started saving build plugins
9:18:09 AM: Finished saving build plugins
9:18:09 AM: Started saving pip cache
9:18:09 AM: Finished saving pip cache
9:18:09 AM: Started saving emacs cask dependencies
9:18:09 AM: Finished saving emacs cask dependencies
9:18:09 AM: Started saving maven dependencies
9:18:09 AM: Finished saving maven dependencies
9:18:09 AM: Started saving boot dependencies
9:18:09 AM: Finished saving boot dependencies
9:18:09 AM: Started saving rust rustup cache
9:18:09 AM: Finished saving rust rustup cache
9:18:09 AM: Started saving go dependencies
9:18:09 AM: Finished saving go dependencies
9:18:13 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:18:13 AM: Failing build: Failed to build site
9:18:13 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
9:18:13 AM: Finished processing build request in 1m26.996184038s

Ok, so, what I read in your output is that modules are not loaded (at all). We are sure that you have a current Hugo version set (0.80/extended) so let’s see your netlify.toml and your config.toml to see why Hugo is ignoring modules on production.

Your problem is this:

[[module.mounts]]
source = "node_modules/macy/dist/macy.js"
target = "assets/js/macy.js"

... more stuff ...

[[module.mounts]]
source = "assets"
target = "assets"

The lower mount overrides the upper mount. It should (should, because not tested) be possible that it starts working if you move the node mount below assets. Hugo reads from the top to the bottom and more general mounts override more specific mounts. There is a ticket on Github (will update this here when I find it) about this that might change this behaviour in a bit.

Edit: that’s not the issue I remember, but it comes near:

Thanks - No - it was originally like this and tried reordering already as well as being specific with all folders. Still same errors.

Well, as I wrote: It overrides each other. You need to structure your assets folder better/different. For instance:

[[module.mounts]]
source = "node_modules/macy/dist/macy.js"
target = "assets/libaries/macy.js"

[[module.mounts]]
source = "someotherpath"
target = "assets/js"

Then have nothing in assets, what you had in assets move to “someotherpath” and the mounts should not interfere with each other. You need to update a lot of paths in your scripts/layouts then probably, but it should start working.

Or move everything inside of assets into assets/js and remove the second mount.

The trick is to mount next to each other, not inside of a mount.

Ah - I think I get it. Great, will try.

No - this isn’t working on a Netlify build still but is happy on local machine. You’re right, the only way to get this working is to have 1 mount, so back to the beginning, the only way to get this to build is manually copy over the macy.js folder from the node_modules.

I remember on Netlify, that it did not load things in the devDeps-part of the packages because it thought it’s a production environment. Check that you have your dependencies not in dev and if and what production environment you define for NPM.

That’s not working either. I need to rethink this, as for a intended low maintenance build, it’s expensive. Help appreciated thanks!