AWS 代码管道构建失败,模块构建失败

如何解决AWS 代码管道构建失败,模块构建失败

我的 angular 项目似乎突然无法在 AWS Code Build 上构建。在我对项目进行更改之前,我什至恢复了提交(这些更改无论如何都不会影响包或构建命令,但我认为我只是以防万一发生了变化)。当我在我的机器上使用 ng build --prod 构建时,它构建得很好,但是当 AWS Code Build 在管道执行期间运行时,它会引发此错误

Error: ./src/main.ts
Module build Failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getResourceDependencies(...) is not a function or its return value is not iterable
    at getDependencies (/codebuild/output/src145253754/src/node_modules/@ngtools/webpack/src/ivy/plugin.js:261:56)
    at /codebuild/output/src145253754/src/node_modules/@ngtools/webpack/src/ivy/plugin.js:374:20
    at analyzingFileEmitter (/codebuild/output/src145253754/src/node_modules/@ngtools/webpack/src/ivy/plugin.js:307:20)
    at process._tickCallback (internal/process/next_tick.js:68:7)
 @ multi ./src/main.ts main[0]

Error: ./src/polyfills.ts
Module build Failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js):
TypeError: angularCompiler.getResourceDependencies(...) is not a function or its return value is not iterable
    at getDependencies (/codebuild/output/src145253754/src/node_modules/@ngtools/webpack/src/ivy/plugin.js:261:56)
    at /codebuild/output/src145253754/src/node_modules/@ngtools/webpack/src/ivy/plugin.js:374:20
    at analyzingFileEmitter (/codebuild/output/src145253754/src/node_modules/@ngtools/webpack/src/ivy/plugin.js:307:20)
    at process._tickCallback (internal/process/next_tick.js:68:7)
 @ multi ./node_modules/@angular-devkit/build-angular/src/webpack/es5-polyfills.js zone.js/dist/zone-legacy ./src/polyfills.ts polyfills-es5[2]



[Container] 2021/01/23 16:26:06 Command did not exit successfully ng build --prod exit status 1
[Container] 2021/01/23 16:26:06 Phase complete: BUILD State: Failed
[Container] 2021/01/23 16:26:06 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: ng build --prod. Reason: exit status 1

这是 package.json 文件

{
  "name": "kingand-queen","version": "0.0.0","scripts": {
    "ng": "ng","dev": "eslint 'src/**/*.ts' && ng serve","build": "ng build","test": "ng test","lint": "eslint 'src/**/*.ts'","e2e": "ng e2e"
  },"private": true,"dependencies": {
    "@angular/animations": "^10.0.14","@angular/cdk": "^9.2.4","@angular/common": "^10.0.14","@angular/compiler": "^10.0.14","@angular/core": "^10.0.14","@angular/flex-layout": "^10.0.0-beta.32","@angular/forms": "^10.0.14","@angular/google-maps": "^10.2.7","@angular/localize": "^10.0.14","@angular/material": "^9.1.0","@angular/platform-browser": "^10.0.14","@angular/platform-browser-dynamic": "^10.0.14","@angular/router": "^10.0.14","@mdi/font": "^5.8.55","@ng-bootstrap/ng-bootstrap": "^6.1.0","@syncfusion/ej2-angular-calendars": "^18.3.48","@syncfusion/ej2-material-theme": "~17.2.48","@types/googlemaps": "3.39.14","aos": "^2.3.4","bootstrap": "^4.5.3","component": "^1.1.0","cookieconsent": "^3.1.1","hammerjs": "^2.0.8","jquery": "^3.4.1","moment": "^2.29.1","ng-gallery": "^5.0.0","ng-recaptcha": "^5.0.0","ngx-cookie-service": "^10.1.1","ngx-cookieconsent": "^2.2.3","ngx-gallery": "^5.10.0","ngx-lightBox": "^2.2.2","ngx-socket-io": "^3.2.0","rxjs": "~6.5.4","tslib": "^1.14.1","zone.js": "~0.10.2"
  },"devDependencies": {
    "@angular-devkit/build-angular": "^0.901.12","@angular-eslint/eslint-plugin": "0.0.1-alpha.32","@angular/cli": "^10.2.0","@angular/compiler-cli": "^10.0.14","@angular/language-service": "^10.0.14","@ngrx/schematics": "^9.1.0","@types/aos": "^3.0.3","@types/jasmine": "^3.5.14","@types/jasminewd2": "~2.0.3","@types/jquery": "^3.5.4","@types/node": "^12.19.6","@typescript-eslint/eslint-plugin": "^3.10.1","@typescript-eslint/parser": "^3.10.1","codelyzer": "^5.1.2","eslint": "^7.13.0","jasmine-core": "~3.5.0","jasmine-spec-reporter": "~4.2.1","karma": "~4.4.1","karma-chrome-launcher": "~3.1.0","karma-coverage-istanbul-reporter": "~2.1.0","karma-jasmine": "~3.0.1","karma-jasmine-html-reporter": "^1.4.2","node-sass": "^4.14.1","protractor": "~5.4.3","ts-node": "~8.3.0","tslint": "^6.1.3","typescript": "^3.9.7"
  }
}

这是我的 tsconfig.json:

{
  "compileOnSave": false,"compilerOptions": {
    "baseUrl": "./","outDir": "./dist/out-tsc","sourceMap": true,"declaration": false,"downlevelIteration": true,"experimentalDecorators": true,"module": "esnext","moduleResolution": "node","importHelpers": true,"target": "es2015","lib": [
      "es2018","dom"
    ]
  },"angularCompilerOptions": {
    "fullTemplateTypeCheck": true,"strictInjectionParameters": true
  }
}

这是我的 tsconfig.app.json:

{
  "extends": "./tsconfig.json","compilerOptions": {
    "outDir": "./out-tsc/app","types": []
  },"files": [
    "src/main.ts","src/polyfills.ts"
  ],"include": [
    "src/**/*.d.ts"
  ]
}

最后,我的 buildspec.yml:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing angular cli...
      - npm install -g @angular/cli
      - yarn add @angular-devkit/build-angular --dev
  build:
    commands:
      - echo Build started...
      - ng build --prod
artifacts:
  files:
    - '**/*'
  base-directory: dist/KingandQueen

现在我不知道为什么会突然发生这种情况我过去已经构建了该项目大约 50 次,直到今天都没有出现任何问题,而没有故意执行可能导致此问题的更新。我已经搜索了 GitHub 错误日志和堆栈溢出,但在此问题上找不到任何内容,因此不胜感激。

解决方法

经过数小时扫描 GitHub、堆栈溢出和搜索 @ngtools/webpack/src/ivy/plugin.js 的所有其他各种结果后,我找到了一个可能与我有类似问题的人的结果......但是,这可能是一个延伸因为他似乎只在他/她的本地机器上触发,并且只在运行 npm audit fix (Errors after npm audit fix angular 10.0.1) 时触发。这是一篇最近的帖子,所以我假设它一定是最近的包问题或依赖冲突,最有可能与 @ngtools/webpack@angular/compiler 有关。然而,这是基于日志的一种猜测,但在查看我的本地机器时,抱怨 node_modules/@ngtools/webpack/src/ivy/plugin.js 的文件尚不存在,但尚未完美构建。因此,经过数小时或删除、更新和降级各种软件包、删除我的 node_modules 并重建我的 package-lock.json 文件后,似乎仍然没有任何效果,但无论我对 package.json 进行了哪些更改,它都可以在我的机器上完美运行。所以我转向我的 buildspec.yml 并在反复试验后奇迹般地解决了构建问题。这是我的工作构建规范:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - echo Installing source NPM dependencies...
      - npm install -y npm@latest
      - npm install -g @angular/cli
      - rm package-lock.json
    pre_build:
      commands:
      - npm install
  build:
    commands:
      - echo Build started...
      - ng build --prod
artifacts:
  files:
    - '**/*'
  base-directory: dist/KingandQueen

我相信,而且我很容易在这里被误导,由于某种原因,安装在 @angular/cli 阶段的最新版本的 install 导致了该问题,因此删除了 package-lock.json在安装阶段手动确保全新安装,npm install 确保 package-lock.json 是全新制作的。

我仍然没有完全了解这个循环,但在检查时,它似乎在我的 AWS 账户中用 angular 困扰了我所有的代码管道,该账户具有多个不同的 angular 项目。确实很奇怪,它基本上是在过去 6 个月(项目的 50 多个版本)没有大惊小怪之后突然冒出来的。无论如何,很高兴能够找到那个问题的根源......我希望这对其他可能遇到这个问题的人有所帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?