SCSS compilation on Netlify broken (and I can't understand what is happening)

For some days now my Netlify builds suddenly break when creating a stylesheet from some SCSS. The error is as evading as possible and I have no memory of changing anything in the process.

Hugo version: 0.79.0 via netlify.toml

The error that comes up (with no previous or following warning or additional notices) is:

7:46:05 PM: Error: Error building site: POSTCSS: failed to transform "style.css" (text/css): resource "scss/theme.scss_7be65e57abd2a821d9a0a498759275a5" not found in file cache

The partial creating the stylesheet:

{{ $options := (dict "targetPath" "style.css" "outputStyle" "compressed" "enableSourceMap" true "precision" 6 "includePaths" (slice "node_modules")) }}
{{ $style := resources.Get "theme.scss" | resources.ToCSS $options | resources.PostCSS (dict "config" "postcss.config.js") | resources.Minify |  resources.Fingerprint "sha512" }}
{{ return $style }}

In my understanding the fact that PostCSS does not find theme.scss-cachekey points to resources.ToCSS $options being the culprit. I would however expect some more verbosity before the error that says something like β€œcould not find file to import” or something else wrong in the SCSS process.

Not happening. I am very lost :wink: Where should I apply the crowbar?

By the way, locally it works, no error, no notice.

I’m guessing you have for some reason gotten a very old Netlify build image, which does not support the extended Hugo version.

1 Like

Related to PostCSS hash issue on Netlify [solved] ?

1 Like

I guess you’re right.

For my (old) first Netlify site I had to add those 2 lines. The newer ones were fine.

GO_VERSION = "1.14.4"
NODE_VERSION = "12.2.0"
1 Like

@bep no, it’s the latest. I am paranoid about that these days, hehe

@pointyfar I remember β€œsimplifying” the netlify.toml… and yeah, there was a NODE_ENV in there. And that is indeed the solution.

So for posterities sake: Setting NODE_ENV to production resulted in most of my npm packages not being available because they were set as devDependencies (my conspiracy theory)… sometimes it’s so easy. And sometimes it’s better to not just add all the available config parameters :smiley:

netlify.toml
[build]
publish = "public"
command = "./bin/netlify.sh"

[build.environment]
TZ = "Asia/Bangkok"
HUGO_VERSION = "0.79.0"
HUGO_ENV = "production"
NODE_VERSION = "14.14.0"
NPM_VERSION = "6.14.8"
NODE_ENV = "production"
GO_VERSION = "1.15"
build log
7:42:29 PM: Build ready to start
7:42:31 PM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41
7:42:31 PM: build-image tag: v3.5.0
7:42:31 PM: buildbot version: cc43e42ec44f57fc7c434bc20ef842caf4073be1
7:42:31 PM: Building without cache
7:42:31 PM: Starting to prepare the repo for build
7:42:31 PM: No cached dependencies found. Cloning fresh repo
7:42:31 PM: git clone https://github.com/davidsneighbour/samui-samui.de
7:43:41 PM: Preparing Git Reference refs/heads/main
7:43:43 PM: Starting build script
7:43:44 PM: Installing dependencies
7:43:44 PM: Python version set to 2.7
7:43:45 PM: Downloading and installing node v14.14.0...
7:43:45 PM: Downloading https://nodejs.org/dist/v14.14.0/node-v14.14.0-linux-x64.tar.xz...
7:43:45 PM: Computing checksum with sha256sum
7:43:46 PM: Checksums matched!
7:43:49 PM: Now using node v14.14.0 (npm v6.14.8)
7:43:49 PM: Started restoring cached build plugins
7:43:49 PM: Finished restoring cached build plugins
7:43:49 PM: Attempting ruby version 2.6.2, read from environment
7:43:50 PM: Using ruby version 2.6.2
7:43:50 PM: Using PHP version 5.6
7:43:50 PM: Started restoring cached node modules
7:43:50 PM: Finished restoring cached node modules
7:43:51 PM: Installing NPM modules using NPM version 6.14.8
7:43:55 PM: npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
7:43:59 PM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
7:44:01 PM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
7:44:04 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
7:44:04 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
7:44:15 PM: npm notice created a lockfile as package-lock.json. You should commit this file.
7:44:15 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/chokidar/node_modules/fsevents):
7:44:15 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7:44:15 PM: audited 2259 packages in 23.748s
7:44:16 PM: found 0 vulnerabilities
7:44:16 PM: NPM modules installed
7:44:16 PM: Installing Hugo 0.79.0
7:44:18 PM: Hugo Static Site Generator v0.79.0-1415EFDC/extended linux/amd64 BuildDate: 2020-11-27T09:16:17Z
7:44:18 PM: Started restoring cached go cache
7:44:18 PM: Finished restoring cached go cache
7:44:18 PM: Installing Go version 1.15
7:44:23 PM: unset GOOS;
7:44:23 PM: unset GOARCH;
7:44:23 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.15.linux.amd64';
7:44:23 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.15.linux.amd64/bin:${PATH}";
7:44:23 PM: go version >&2;
7:44:23 PM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.15.linux.amd64.env"
7:44:23 PM: go version go1.15 linux/amd64
7:44:23 PM: Installing missing commands
7:44:23 PM: Verify run directory
7:44:25 PM: ​
7:44:25 PM: ────────────────────────────────────────────────────────────────
7:44:25 PM:   Netlify Build                                                 
7:44:25 PM: ────────────────────────────────────────────────────────────────
7:44:25 PM: ​
7:44:25 PM: ❯ Version
7:44:25 PM:   @netlify/build 5.4.0
7:44:25 PM: ​
7:44:25 PM: ❯ Flags
7:44:25 PM:   deployId: 5fc78bb510d9259a9b69ea77
7:44:25 PM:   mode: buildbot
7:44:25 PM: ​
7:44:25 PM: ❯ Current directory
7:44:25 PM:   /opt/build/repo
7:44:25 PM: ​
7:44:25 PM: ❯ Config file
7:44:25 PM:   /opt/build/repo/netlify.toml
7:44:25 PM: ​
7:44:25 PM: ❯ Context
7:44:25 PM:   production
7:44:25 PM: ​
7:44:25 PM: ────────────────────────────────────────────────────────────────
7:44:25 PM:   1. build.command from netlify.toml                            
7:44:25 PM: ────────────────────────────────────────────────────────────────
7:44:25 PM: ​
7:44:25 PM: $ ./bin/netlify.sh
7:44:25 PM: Update module in /opt/build/repo
7:44:27 PM: hugo: downloading modules …
7:44:35 PM: hugo: collected modules in 9539 ms
7:44:37 PM: Start building sites …
7:44:37 PM: WARN 2020/12/02 19:44:37 Unused hook available for setup (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:37 PM: WARN 2020/12/02 19:44:37 Unused hook available for head-start (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for body-start (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for container-start (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for content-start (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for content-end (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for sidebar-start (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for sidebar-end (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for container-end (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:44:38 PM: WARN 2020/12/02 19:44:38 Unused hook available for body-end (see https://github.com/davidsneighbour/dnb-hugo-garuda/wiki/Content-Hooks)
7:46:05 PM: Total in 88765 ms
7:46:05 PM: Error: Error building site: POSTCSS: failed to transform "style.css" (text/css): resource "scss/theme.scss_7be65e57abd2a821d9a0a498759275a5" not found in file cache
7:46:05 PM: ​
7:46:05 PM: (build.command completed in 1m 40s)
7:46:05 PM: ​
7:46:05 PM: ────────────────────────────────────────────────────────────────
7:46:05 PM:   Netlify Build Complete                                        
7:46:05 PM: ────────────────────────────────────────────────────────────────
7:46:05 PM: ​
7:46:05 PM: (Netlify Build completed in 1m 40.1s)
7:46:05 PM: Caching artifacts
7:46:05 PM: Started saving node modules
7:46:05 PM: Finished saving node modules
7:46:05 PM: Started saving build plugins
7:46:05 PM: Finished saving build plugins
7:46:05 PM: Started saving pip cache
7:46:05 PM: Finished saving pip cache
7:46:05 PM: Started saving emacs cask dependencies
7:46:06 PM: Finished saving emacs cask dependencies
7:46:06 PM: Started saving maven dependencies
7:46:06 PM: Finished saving maven dependencies
7:46:06 PM: Started saving boot dependencies
7:46:06 PM: Finished saving boot dependencies
7:46:06 PM: Started saving go dependencies
7:46:07 PM: Finished saving go dependencies
7:46:11 PM: Build script success
7:46:11 PM: Starting to deploy site from 'public'
7:46:12 PM: Creating deploy tree asynchronously
7:46:13 PM: Creating deploy upload records
7:46:15 PM: 2748 new files to upload
7:46:15 PM: 0 new functions to upload
7:47:46 PM: Starting post processing
7:47:46 PM: Post processing - HTML
7:48:50 PM: Finished processing build request in 6m18.896962726s
7:52:50 PM: Post processing - header rules
7:52:50 PM: Post processing - redirect rules
7:52:50 PM: Post processing done
7:52:50 PM: Site is live ✨

Thank you. One issue less…

Glad you solve the issue.

But i think you have no control on what’s inside your ground Netlify image.
All my sites have the same setup/conf but the oldest site is not exactly the same than the latter ones. Hence the explicit versions.

1 Like

Yep. Check my netlify.toml above. I started to be very explicit with versions so I can be 100% sure what is going on. I think the recent major postcss release was what made me do this because somehow the local/global/netlify node version got mixed up.

I have an eye on releases of the netlify images on Github (https://github.com/netlify/build-image), but most of the explanations are gobbelydook to me. They have a list of used versions though:

To go even deeper on this, here is my β€œphilosophy” on npm packages (not sure if they make sense and I am pretty sure this might be a weird position because the first point is something nobody ever tells you to do:

  • I NEVER add the package-lock.json to my repositories. Git ignore it.
  • I NEVER add a β€œrelative” version to my packages. So no β€œ~1.0.0” or β€œ^1.0.0”. It’s ALWAYS a fixed static version number like β€œ1.0.0”
  • I ALWAYS configure @dependabot on Github to either daily or weekly check my packages and update version numbers. The bot will create pull requests with updates of versions.

In my philosophy:

  • Patch releases are ok to β€œblindly” (ok, I read the changelog/commits information on these pull requests to know what changed, but I trust that they won’t break because β€œdon’t patch release if you don’t commit to adhere to semver”) merge
  • Minor releases need some β€œbrain resources” to read through the changes and decide if I can merge them blindly or need to test and adapt (git pull, checkout pull request branch, check if hugo runs, be happy and merge)
  • Major releases have to be thoroughly tested and changes in those releases understood, then merged.

This takes maybe 10 minutes a day for all my projects.

Why not committing package-lock.json? Because back when I did that it resulted in merge conflicts in the file that ALWAYS had to have manual edits to the files. There is a lot of hashing going on in that file and that never works out if it needs to be merged.

My way works nice (for me). I had a little stumble when PostCSS had a major release because it released one day and the plugins released the day after and that one day between nothing worked. But that’s just something one has to lived through to remember it for the next time. And with weekly checks it’s not too obvious next time.

Samples:

Config for dependabot: https://github.com/davidsneighbour/dnb-hugo-garuda-template/blob/main/.github/dependabot.yml
A static package.json: https://github.com/davidsneighbour/dnb-hugo-garuda-template/blob/main/package.json

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.