Get colored console output in Netlify logs with this One Weird Trick!

Sometimes you may see colored output in your local development which loses its color when you run it in Netlify deploy logs. Today (2 years in using Netlify) I learned that it’s not Netlify’s fault! Some popular output coloring libraries like chalk detect if they are in a CI environment and turn off colors!

To force it on, you can set a FORCE_COLOR environment variable = true as per the underlying supports-color library.

see this in action here https://app.netlify.com/sites/musing-keller-262812/deploys/5d658208ded2b300087bfa0e (source)

5 Likes

Looks like it’s not compatible with Gatsby — my builds fails for no reason when I add FORCE_COLOR=true, and it stops failing when I remove it.

11:20:03 AM: Finished saving go dependencies
11:20:06 AM: Error running command: Build script returned non-zero exit code: 127
11:20:06 AM: Failing build: Failed to build site
11:20:06 AM: failed during stage 'building site': Build script returned non-zero exit code: 127
11:20:06 AM: Finished processing build request in 1m4.943530499s

If you’d like to link us to your build, that’s probably some misapplication of the value, rather than the value itself breaking your build.

The build URL is https://app.netlify.com/sites/lebikini/deploys/5d67982d3834d472ecd540ea but not sure you can access it so here is the full output:

11:17:33 AM: Build ready to start
11:17:36 AM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
11:17:36 AM: build-image tag: v3.3.2
11:17:36 AM: buildbot version: f71b4aa1b1ebc2bff806e48691024e0ab383dc02
11:17:36 AM: Fetching cached dependencies
11:17:36 AM: Starting to download cache of 304.8MB
11:17:39 AM: Finished downloading cache in 2.320720705s
11:17:39 AM: Starting to extract cache
11:17:54 AM: Finished extracting cache in 15.72568195s
11:17:54 AM: Finished fetching cache in 18.243534738s
11:17:54 AM: Starting to prepare the repo for build
11:17:55 AM: Preparing Git Reference refs/heads/master
11:17:56 AM: Found netlify.toml. Overriding site configuration
11:17:56 AM: Starting build script
11:17:56 AM: Installing dependencies
11:17:57 AM: Started restoring cached node version
11:18:01 AM: Finished restoring cached node version
11:18:02 AM: v8.16.1 is already installed.
11:18:04 AM: Now using node v8.16.1 (npm v6.4.1)
11:18:04 AM: Attempting ruby version 2.3.6, read from environment
11:18:06 AM: Started restoring cached ruby version
11:18:06 AM: Finished restoring cached ruby version
11:18:09 AM: Using ruby version 2.3.6
11:18:22 AM: Successfully installed bundler-2.0.2
11:18:22 AM: Parsing documentation for bundler-2.0.2
11:18:22 AM: Installing ri documentation for bundler-2.0.2
11:18:22 AM: Done installing documentation for bundler after 11 seconds
11:18:22 AM: 1 gem installed
11:18:22 AM: Using PHP version 5.6
11:18:22 AM: Started restoring cached node modules
11:18:22 AM: Finished restoring cached node modules
11:18:22 AM: Started restoring cached yarn cache
11:18:22 AM: Finished restoring cached yarn cache
11:18:23 AM: Installing NPM modules using Yarn version 1.3.2
11:18:24 AM: 
11:18:24 AM: 
11:18:24 AM: yarn install v1.3.2
11:18:25 AM: 
11:18:25 AM: [1/5] Validating package.json...
11:18:25 AM: 
11:18:25 AM: [2/5] Resolving packages...
11:18:26 AM: 
11:18:26 AM: success Already up-to-date.
11:18:26 AM: 
11:18:26 AM: Done in 2.07s.
11:18:26 AM: NPM modules installed using Yarn
11:18:27 AM: Started restoring cached go cache
11:18:29 AM: Finished restoring cached go cache
11:18:29 AM: Installing Go version 1.10
11:18:30 AM: unset GOOS;
11:18:30 AM: unset GOARCH;
11:18:30 AM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64';
11:18:30 AM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64/bin:${PATH}";
11:18:30 AM: go version >&2;
11:18:30 AM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.10.linux.amd64.env';
11:18:30 AM: go version go1.10 linux/amd64
11:18:30 AM: Installing missing commands
11:18:30 AM: Verify run directory
11:18:30 AM: Executing user command: gatsby build
11:18:30 AM: /usr/local/bin/build: line 60: gatsby: command not found
11:18:30 AM: Skipping functions preparation step: no functions directory set
11:18:30 AM: Caching artifacts
11:18:30 AM: Started saving node modules
11:18:30 AM: Finished saving node modules
11:18:30 AM: Started saving yarn cache
11:18:30 AM: Finished saving yarn cache
11:18:30 AM: Started saving pip cache
11:18:30 AM: Finished saving pip cache
11:18:30 AM: Started saving emacs cask dependencies
11:18:30 AM: Finished saving emacs cask dependencies
11:18:30 AM: Started saving maven dependencies
11:18:30 AM: Finished saving maven dependencies
11:18:30 AM: Started saving boot dependencies
11:18:30 AM: Finished saving boot dependencies
11:18:30 AM: Started saving go dependencies
11:18:32 AM: Finished saving go dependencies
11:18:33 AM: Error running command: Build script returned non-zero exit code: 127
11:18:33 AM: Failing build: Failed to build site
11:18:33 AM: failed during stage 'building site': Build script returned non-zero exit code: 127
11:18:33 AM: Finished processing build request in 56.698128643s

Compared to the fixed one: https://app.netlify.com/sites/lebikini/deploys/5d6798b4e0c7ae1c47cdacc5

11:19:48 AM: Waiting to build. Currently running 1 concurrent builds on your account
11:19:48 AM: Build ready to start
11:19:50 AM: build-image version: 9e0f207a27642d0115b1ca97cd5e8cebbe492f63
11:19:50 AM: build-image tag: v3.3.2
11:19:50 AM: buildbot version: f71b4aa1b1ebc2bff806e48691024e0ab383dc02
11:19:51 AM: Fetching cached dependencies
11:19:51 AM: Starting to download cache of 304.8MB
11:19:52 AM: Finished downloading cache in 1.518675031s
11:19:52 AM: Starting to extract cache
11:20:07 AM: Finished extracting cache in 14.874064206s
11:20:07 AM: Finished fetching cache in 16.555335837s
11:20:07 AM: Starting to prepare the repo for build
11:20:11 AM: Preparing Git Reference refs/heads/master
11:20:12 AM: Found netlify.toml. Overriding site configuration
11:20:12 AM: Starting build script
11:20:12 AM: Installing dependencies
11:20:13 AM: Started restoring cached node version
11:20:16 AM: Finished restoring cached node version
11:20:17 AM: v8.16.1 is already installed.
11:20:18 AM: Now using node v8.16.1 (npm v6.4.1)
11:20:18 AM: Attempting ruby version 2.3.6, read from environment
11:20:19 AM: Started restoring cached ruby version
11:20:19 AM: Finished restoring cached ruby version
11:20:22 AM: Using ruby version 2.3.6
11:20:33 AM: Successfully installed bundler-2.0.2
11:20:33 AM: Parsing documentation for bundler-2.0.2
11:20:33 AM: Installing ri documentation for bundler-2.0.2
11:20:33 AM: Done installing documentation for bundler after 9 seconds
11:20:33 AM: 1 gem installed
11:20:33 AM: Using PHP version 5.6
11:20:33 AM: Started restoring cached node modules
11:20:33 AM: Finished restoring cached node modules
11:20:33 AM: Started restoring cached yarn cache
11:20:33 AM: Finished restoring cached yarn cache
11:20:34 AM: Installing NPM modules using Yarn version 1.3.2
11:20:35 AM: yarn install v1.3.2
11:20:35 AM: [1/5] Validating package.json...
11:20:35 AM: [2/5] Resolving packages...
11:20:36 AM: success Already up-to-date.
11:20:36 AM: Done in 1.44s.
11:20:36 AM: NPM modules installed using Yarn
11:20:37 AM: Started restoring cached go cache
11:20:39 AM: Finished restoring cached go cache
11:20:39 AM: Installing Go version 1.10
11:20:39 AM: unset GOOS;
11:20:39 AM: unset GOARCH;
11:20:39 AM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64';
11:20:39 AM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.10.linux.amd64/bin:${PATH}";
11:20:39 AM: go version >&2;
11:20:39 AM: export GIMME_ENV='/opt/buildhome/.gimme_cache/env/go1.10.linux.amd64.env';
11:20:39 AM: go version go1.10 linux/amd64
11:20:39 AM: Installing missing commands
11:20:39 AM: Verify run directory
11:20:39 AM: Executing user command: gatsby build
11:20:42 AM: success open and validate gatsby-configs — 0.061
11:20:58 AM: success load plugins — 15.563
11:20:58 AM: success onPreInit — 0.089
11:20:58 AM: success delete html and css files from previous builds — 0.076
11:20:59 AM: success initialize cache — 0.479
11:20:59 AM: success copy gatsby files — 0.171
11:20:59 AM: success onPreBootstrap — 0.426
11:22:37 AM: success source and transform nodes — 97.965
11:22:40 AM: warning Deprecation warning - adding inferred resolver for field BikiniEvent.image. In Gatsby v3, only fields with an explicit directive/extension will get a resolver.
11:22:40 AM: warning Deprecation warning - adding inferred resolver for field BikiniEvent.place. In Gatsby v3, only fields with an explicit directive/extension will get a resolver.
11:22:40 AM: warning Deprecation warning - adding inferred resolver for field BikiniBanner.image. In Gatsby v3, only fields with an explicit directive/extension will get a resolver.
11:22:40 AM: warning Deprecation warning - adding inferred resolver for field BikiniAd.image. In Gatsby v3, only fields with an explicit directive/extension will get a resolver.
11:22:40 AM: success building schema — 3.297
11:22:45 AM: success createPages — 4.110
11:22:45 AM: success createPagesStatefully — 0.848
11:22:45 AM: success onPreExtractQueries — 0.116
11:22:46 AM: success update schema — 0.133
11:22:47 AM: success extract queries from components — 1.095
11:22:47 AM: success write out requires — 0.173
11:22:47 AM: success write out redirect data — 0.152
11:22:47 AM: success Build manifest and related icons — 0.397
11:22:48 AM: success onPostBootstrap — 0.507
11:22:48 AM: info bootstrap finished - 128.721 s
11:22:53 AM: success run static queries — 5.485 — 9/9 1.68 queries/second
11:23:39 AM: success Generating image thumbnails — 469/469 - 51.645 s
11:23:46 AM: success Building production JavaScript and CSS bundles — 52.409
11:23:46 AM: success Rewriting compilation hashes — 0.169
11:23:57 AM: success run page queries — 10.312 — 151/151 15.04 queries/second
11:24:36 AM: success Generating image thumbnails — 893/893 - 50.162 s
11:24:45 AM: success Building static HTML for pages — 8.416 — 151/151 41.00 pages/second
11:24:54 AM: Algolia batch: 12 updates
11:24:54 AM: Sentry release: ALREADY REPORTED
11:24:54 AM: Sentry deploy: CREATED
11:24:54 AM: info Done building in 255.347 sec
11:24:55 AM: Skipping functions preparation step: no functions directory set
11:24:55 AM: Caching artifacts
11:24:55 AM: Started saving node modules
11:24:55 AM: Finished saving node modules
11:24:55 AM: Started saving yarn cache
11:24:55 AM: Finished saving yarn cache
11:24:55 AM: Started saving pip cache
11:24:55 AM: Finished saving pip cache
11:24:55 AM: Started saving emacs cask dependencies
11:24:55 AM: Finished saving emacs cask dependencies
11:24:55 AM: Started saving maven dependencies
11:24:55 AM: Finished saving maven dependencies
11:24:55 AM: Started saving boot dependencies
11:24:55 AM: Finished saving boot dependencies
11:24:55 AM: Started saving go dependencies
11:24:57 AM: Finished saving go dependencies
11:24:57 AM: Build script success
11:24:57 AM: Starting to deploy site from 'public/'
11:25:00 AM: Creating deploy tree asynchronously
11:25:12 AM: 339 new files to upload
11:25:12 AM: 0 new functions to upload
11:25:27 AM: Starting post processing
11:26:32 AM: Finished processing build request in 6m41.493140216s
11:27:13 AM: Post processing done
11:27:14 AM: Site is live

hi @antoinerousseau - thanks for your patience. We started looking into this issue - but its beyond our bandwidth to be looking into this just now, i’m afraid. If you’d like to keep digging and come up with a solution, please post it here! and if we find some time somewhere to take another look, we will do the same. thanks for pointing this out. :muscle: