node.js - 更新到 Angular 8 CLI 后抛出“.getColorDepth 不是函数”
问题描述
我的一位同事将我们的项目升级到 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并不简单。请参阅如何更新 Node.js?. 一些流行的答案位于页面下方,因此值得滚动浏览。
推荐阅读
- sql - I have a problem removing; of a column with the substring in SQL Server
- javascript - Mousemove events don't trigger
- asp.net - WebForm MVP one view to display different controls after each button click
- java - java.lang.NullPointerException Can't set text from class to activity
- regex - 正则表达式匹配从第一个下划线到最后一个下划线的值
- android - onSaveInstanceState0 Doesn't survive Activity Death
- ios - Apple MDM Push notifications are not delivered to devices
- javascript - MongoDB Aggregation not updating my collection
- java - How to highlight a specific word or sentence using PDFBox in Java
- c++ - Is it possible a lock wouldn't release in a while loop