After update to Angular 8 CLI throws ".getColorDepth is not a function"
Asked Answered
D

4

14

A collegue of mine upgraded our project to angular 8. I pulled his branch and run npm install. On his branch everyhing works fine. I do now get the same error every time i run any "ng ..." command:

C:\xxx\party-ui\node_modules\@angular\cli\utilities\color.js:15
    process.stdout.getColorDepth() > 1;
                   ^

    TypeError: process.stdout.getColorDepth is not a function
        at Object.<anonymous> (C:\xxx\party-ui\node_modules\@angular\cli\utilities\color.js:15:20)
        at Module._compile (module.js:652:30)
        at Object.Module._extensions..js (module.js:663:10)
        at Module.load (module.js:565:32)
        at tryModuleLoad (module.js:505:12)
        at Function.Module._load (module.js:497:3)
        at Module.require (module.js:596:17)
        at require (internal/module.js:11:18)
        at Object.<anonymous> (C:\xxx\party-ui\node_modules\@angular\cli\models\analytics.js:18:17)
        at Module._compile (module.js:652:30)

I also tried to update npm and node (now having versions 10.16.0 and 6.9.0). Also removed the node_modules folder and run npm install after that. What can I do?

Dustin answered 16/7, 2019 at 9:38 Comment(3)
This looks like a node versioning problem. Take a look at what version your colleague is using and try with that oneLexi
Thats what we thought too, so I upgraded to the latest node and npm versions. Cant imagine that my old one and the latest one cause the same error message... Unfortunately its a company device and i do not have admin rights to try with the same versions as my colleague todayDustin
I see the problem: you tried to update angular. Never do that. If you do, you must always remember to first delete node_modules, reinstall npm, shave the dog, take out the trash, empty the recycle bin, re-image your device, floss your teeth, uninstall Tinder from your fone, delete your package-lock.json files, and, while you're at it, delete all the .json files from the network - and the cloud, then reinstall nodejs and generate a new angular module from scratch via ng g m and run npm install, and you're good. If that doesn't work, try a reboot - this worked for me 37% of the time.Fairweather
K
19

Look in the problematic file ./node_modules/@angular/cli/utilities/color.js. Notice a comment above the problematic line (15):

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * @license
 * Copyright Google Inc. All Rights Reserved.
 *
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://angular.io/license
 */
 const colors = require("ansi-colors");
 exports.colors = colors;
 const tty_1 = require("tty");
 // Typings do not contain the function call (added in Node.js v9.9.0)
 exports.supportsColor = process.stdout instanceof tty_1.WriteStream &&
    process.stdout.getColorDepth() > 1;
 colors.enabled = exports.supportsColor;

Specifically:

// Typings do not contain the function call (added in Node.js v9.9.0)

Upgrading Node to a version no less than v9.9.0 fixes the problem.

but...

...choosing how to upgrade NodeJS is not necessairly straightforward. See How do I update Node.js?. Some popular answers are quite far down the page so it's worth scrolling through.

Kremlin answered 16/7, 2019 at 17:47 Comment(1)
Thanks, this brought me to the right solution. I had to delete tohe folder of the old node-js version...Dustin
F
3

had the same error,
my versions:

Angular CLI: 8.1.1
Node: 11.14.0
OS: linux x64
Angular: 8.1.1

run:

rm -rf node_modules
rm -rf package-lock.json
sudo npm cache clean --force
npm install
Frankpledge answered 16/7, 2019 at 12:24 Comment(2)
This was unfortunately not solving the problemDustin
this works for linux, for windows you should delete the node_modules directory and package-lock.json file, and then clean the npm cacheFrankpledge
J
0

Had the error occuring with "@angular/core": "~8.2.3".

I updated the node version to the latest stable version using these commands and it fixed the issue for me in linux

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Jasper answered 22/9, 2019 at 8:0 Comment(0)
C
0

I was on an older node.js version in my development machine. Switching my node version from 8 to 12 removed this error for me and my project began building successfully again:

"nvm use 12.16.3"

NVM is a node version manager that will enable you to quickly switch between node versions, and I recommend using it when working on multiple projects of different node versions.

Documentation: https://github.com/nvm-sh/nvm

Carraway answered 26/8, 2020 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.