【问题标题】:TypeError: ansiColors.create is not a function at Object.<anonymous>TypeError: ansiColors.create is not a function at Object.<anonymous>
【发布时间】:2021-08-15 15:46:30
【问题描述】:

帮我解决以下 angular build 问题

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.js?
  • 尝试升级/降级节点版本
  • 我遇到了同样的问题,帮助删除节点模块文件夹并重新安装。

标签: node.js angular build angular8 angularbuild


【解决方案1】:

如果你查看./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版本

【讨论】:

  • 我有同样的问题,版本是 v15.11.0。我不同意解决方案是节点版本至少为 v9.9.0。
  • 同样,我有节点 v10,但它仍然无法正常工作
【解决方案2】:

我今天遇到了这个问题,并且也在使用 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)

【讨论】:

    猜你喜欢
    • 2014-01-26
    • 2020-07-26
    • 2020-06-29
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 2019-09-02
    相关资源
    最近更新 更多