类型错误:ansiColors.create 不是 Object.<anonymous> 处的函数

问题描述

帮助我解决以下角度构建问题

ng build --configuration=qa


/opt/tomcat/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_14.15.0/lib/node_modules/@angular/cli/utilities/color.js:22
const colors = ansiColors.create();
                      ^

TypeError: ansiColors.create is not a function
    at Object.<anonymous> (/opt/tomcat/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_14.15.0/lib/node_modules/@angular/cli/utilities/color.js:22:27)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/opt/tomcat/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/NodeJS_14.15.0/lib/node_modules/@angular/cli/lib/init.js:15:17)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
Build step 'Execute shell' marked build as failure
Finished: FAILURE

解决方法

如果你查看./node_modules/@angular/cli/utilities/color.js,你会发现这句话

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

所以解决方案是至少要有一个 v9.9.0 的 node.js 版本

,

我今天遇到了这个问题,并且也在使用 Jenkins。我通过删除 node_modules 目录解决了这个问题。

之前的脚本:

(cd client/ && npm install)
(cd client/ && npm run build)

新脚本:

(cd client/ && rm -r node_modules)
(cd client/ && npm install)
(cd client/ && npm run build)