node.js - 更新到 Angular 8 CLI 后抛出 ".getColorDepth is not a function"

标签 node.js angular typescript angular8

我的一位同事将我们的项目升级到 Angular 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)

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

最佳答案

查看有问题的文件 ./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;

具体来说:

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

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

但是……

...选择升级方式NodeJS不一定是直截了当的。参见 How do I update Node.js? .一些受欢迎的答案位于页面下方很远的位置,因此值得滚动浏览。

关于node.js - 更新到 Angular 8 CLI 后抛出 ".getColorDepth is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57054305/

相关文章:

angular - TypeScript 阻止我将正确的约束传递给 getUserMedia

reactjs - 如何在 ReactJS 中使用 mobx 组织 typescript

javascript - 为什么 ngStyle 不起作用

javascript - 如何获取表中某一行的值?

javascript - nodejs/js : Only first function of async.系列回调后依然执行

angular - Ionic 4/Angular 6 - 使用拦截器在 401/403 上重定向登录页面

angular - 在 Angular 中从模板中引用属性或 getter 的性能

javascript - Angular 服务不更新订阅的组件

javascript - 如何在 Redirect() 中传递变量 - 但不在 URL 中传递

node.js - 对运行一个非常简单的 socket.io 示例感到困惑?