[Snap] Pipeline error with PostCSS (environment issue?)

I’m trying to use

{{ $styles := resources.Get "style/main.scss" | resources.ToCSS | resources.PostCSS }}

but when I build, I get this error:

INFO 2018/08/14 09:25:25 postcss: use config file /home/jbandlow/Programming/web/followinggradients/postcss.config.js
/usr/bin/env: 'node': No such file or directory
ERROR 2018/08/14 09:25:25 error: failed to transform resource: exit status 127

If I remove the final pipe, everything works, and so I believe that the error is occurring when this code is calling the postcss script:

$ cat node_modules/postcss-cli/bin/postcss 
#!/usr/bin/env node

require('../')

I’ve installed post-css and autoprefixer with npm install -D, and the following works as expected:

node_modules/postcss-cli/bin/postcss static/main.css --config postcss.config.js 

On a lark, I even tried to run postcss from Go. With the following, go run mytest.go works as expected:

// mytest.go
package main

import (
        "fmt"
        "log"
        "os/exec"
)

func main() {
        out, err := exec.Command("node_modules/postcss-cli/bin/postcss", "static/main.css").Output()
        if err != nil {
                log.Fatal(err)
        }
        fmt.Printf("%s", out)
}

My Hugo environment:

$ hugo env
Hugo Static Site Generator v0.46/extended linux/amd64 BuildDate: 2018-08-01T13:25:43Z
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.10.3"

and for whatever it’s worth, it was installed via snap.

I can’t shake the feeling that I’m missing something really silly here, but if so, I just can’t see it. Does anyone have any ideas?

Did you try to globally install the node deps as suggested in the code you linked to?

1 Like

If postcss-cli and autoprefixer are installed both locally and globally, I get the same error. If they are only installed globally, I get

ERROR 2018/08/14 11:17:18 error: failed to transform resource: POSTCSS: failed to transform "style/main.css" (text/css): this feature is not available in your current Hugo version

Not sure what Snap have you but you may have some luck bumping up to the Node 8 LTS if running an old version. Node deps are not well known for backwards compatibility. Use NVM to manage your Node version of you find yourself debugging compatability issues so you don’t pull your hair out.

Please pardon my typos, I’m on a small screen

@jhabdas Thanks for your suggestions. My system node (which I have been using) is v8.10.0, but I tried bumping it up to the LTS (v8.11.3) with nvm, and it didn’t make a difference.

Oof. Based on that last error I’d suspect integration, package or regression given everything else you tried. Not sure how far you want to go but pulling the Hugo binary or trying a Docker build from source might be the next logical step.

I have had that issue many moons ago in the Gulp world. I think this is resolved in newer Node version, but the above suggests a node binary mismatch. I think it was called nodejs at some point – you will find tutorials online about creating symlinks from nodejs to node etc. But I suspect that a upgrade to a newer version of node will also resolve this.

@bep I’ve upgraded my system Node to v10.8.0 and npm to v6.2.0, and (as far as I’m aware) purged all older versions. It’s still the case that everything runs as expected if I run postcss from the command line, or from Gulp, or from my own hacked up Go program (see OP) – it’s only hugo that gives this error.

When I next have a moment, I’ll try building hugo from source in case this is some artifact of installing from snap – in the meantime I welcome any other suggestions of things to look at!

Ok, I’m convinced this was related to details of my Snap installation of Hugo. There are subtleties around the security model (see here and the related issue) that I don’t fully understand, but it appears that when running as a Snap I did not have read permission to /usr/bin or /usr/local/bin. For example, I was getting the following in /var/syslog:

Aug 14 18:28:52 pop-os kernel: [637475.173347] audit: type=1400 audit(1534296532.347:175): apparmor="DENIED" operation="open" profile="/snap/core/5145/usr/lib/snapd/snap-confine" name="/etc/pop-os/os-release" pid=7571 comm="snap-confine" requested_mask="r" denied_mask="r" fsuid=0 ouid=0
Aug 14 18:28:52 pop-os kernel: [637475.175425] audit: type=1400 audit(1534296532.351:176): apparmor="DENIED" operation="open" profile="snap.hugo.hugo" name="/etc/pop-os/os-release" pid=7571 comm="snap-exec" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

I tried removing the snap and re-installing with sudo snap install hugo --classic --channel=extended, but I continued to get the same error. Removing the Snap and installing the 0.46-extended deb-file resolved the issue.

The snap behavior may or may not be a bug, but at this point I have a work-around and I’ve shaved enough yaks for today, so I don’t plan to dig any further. If more knowledgeable folks think it’s broken and would like more info, please tag me and I’d be happy to help.

Thanks all!

1 Like

I remember some permission issues related to Snap and the old Pygments integration, which is similar on the technical level. @anthonyfok may have more info.

1 Like

@jbandlow Sorry for the troubles you experienced, and thank you for your detailed investigation.
@bep Thank you for bringing this to my attention.

I have updated snapcraft.yaml to include nodejs (with /usr/bin/node) into the Hugo snap itself, like how we dealt with Pygments in the past, in commit ef20ec1. It will be available with the next Hugo release (0.47.1 or 0.48). Hope it would remedy the situation.

2 Likes

Update: My previous commit ef20ec1 did not actually fix the issue. Sorry for my inadequate testing.

But I am happy to announce that the very latest Hugo Snap, released today (Aug 24) with revision number 2599 (channel: extended), now comes with a working bin/node and works properly with a locally installed PostCSS installed with npm install postcss-cli without the -g flag. Fixes in commits 2c934be and 66f688f.

1 Like

@anthonyfok I was able to give this a try today and it works great. Thanks so much!

1 Like