更新到Angular 8 CLI后,抛出“ .getColorDepth不是函数”

M.D*_*.D. 4 node.js typescript angular angular8

我的一个同事将我们的项目升级到8号角。我拉了他的分支,然后奔跑npm install。在他的分支上,一切正常。现在,每次运行任何“ ng ...”命令时,我都会得到相同的错误:

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)
Run Code Online (Sandbox Code Playgroud)

我还尝试更新npm和node(现在具有版本10.16.0和6.9.0)。还删除了node_modules文件夹,然后运行npm install。我能做什么?

Jac*_*ack 15

查看有问题的文件./node_modules/@angular/cli/utilities/color.js。请注意有问题的行(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;
Run Code Online (Sandbox Code Playgroud)

特别:

// Typings do not contain the function call (added in Node.js v9.9.0)
Run Code Online (Sandbox Code Playgroud)

将Node升级到不低于v9.9.0的版本可解决此问题。

但...

...选择如何升级的NodeJS不necessairly简单。请参阅如何更新Node.js?。一些流行的答案在页面的下方,因此值得一看。