Angular应用Docker镜像本地构建成功但Azure DevOps构建失败问题排查求助
Angular应用Docker镜像本地构建成功但Azure DevOps构建失败问题排查求助
各位大佬好,我最近碰到个头疼的问题:本地构建Angular应用的Docker镜像一切正常,但在Azure DevOps流水线中执行ng build --configuration production命令时直接失败了。下面是我的相关配置文件和报错日志,麻烦大家帮忙看看问题出在哪?
我的package.json文件内容
{ "name": "candidate-portal", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", "analyze": "webpack-bundle-analyzer dist/CandidatePortal/stats.json", "gzipper": "gzipper", "compress": "npx gzipper compress ./dist", "build-gzip": "gzipper compress ./dist ./dist/gipped", "bundle-report": "webpack-bundle-analyzer dist/CandidatePortal/stats.json", "postinstall": "ngcc", "postbuild": "gulp compress" }, "private": true, "dependencies": { "@angular/animations": "^11.0.9", "@angular/cdk": "^11.0.3", "@angular/common": "^11.0.9", "@angular/compiler": "^11.0.9", "@angular/core": "^11.0.9", "@angular/forms": "^11.0.9", "@angular/http": "^7.2.16", "@angular/localize": "^11.2.0", "@angular/material": "^11.0.3", "@angular/platform-browser": "^11.0.9", "@angular/platform-browser-dynamic": "^11.0.9", "@angular/router": "^11.0.9", "@ctrl/ngx-emoji-mart": "^4.1.0", "@ng-bootstrap/ng-bootstrap": "^8.0.2", "@ng-idle/core": "^10.0.0-beta.1", "@ng-idle/keepalive": "^10.0.0-beta.1", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "^6.0.0", "angular-calendar": "^0.26.1", "angular-file": "^3.4.0", "bootstrap": "4.1.3", "classlist.js": "^1.1.20150312", "core-js": "^3.8.2", "crypto-js": "^4.0.0", "css-loader": "^2.1.0", "date-fns": "^1.29.0", "dayjs": "^1.10.3", "dayjs-ext": "^2.2.0", "feather-icons": "^4.28.0", "file-saver": "^2.0.5", "font-awesome": "^4.7.0", "formdata-polyfill": "^3.0.20", "jquery": "^3.5.1", "jquery-datetimepicker": "^2.5.20", "jquery-typeahead": "^2.11.1", "jquery-ui-dist": "^1.12.1", "lodash": "^4.17.20", "moment": "^2.29.1", "moment-timezone": "^0.5.32", "ng2-file-upload": "1.4.0", "ng2-pdf-viewer": "6.3.2", "ng2-signalr": "^10.1.0", "ngx-bootstrap": "^6.2.0", "ngx-image-cropper": "^3.3.5", "ngx-infinite-scroll": "^10.0.1", "npm": "^9.8.0", "popper": "^1.0.1", "popper.js": "^1.16.1", "postcss-loader": "^2.1.6", "primeng": "^11.1.0", "rxjs": "^6.6.3", "signalr": "^2.3.0", "source-map-explorer": "^2.5.2", "sweetalert2": "^7.26.28", "tslib": "^2.1.0", "zone.js": "^0.11.3" }, "devDependencies": { "@angular-devkit/build-angular": "~0.1100.7", "@angular/cli": "^11.0.7", "@angular/compiler-cli": "^11.0.9", "@angular/language-service": "^11.0.9", "@angular/localize": "^11.2.4", "@schematics/angular": "^11.0.7", "@types/jasmine": "~3.6.2", "@types/jasminewd2": "~2.0.3", "@types/lodash": "^4.14.168", "@types/node": "~14.14.20", "codelyzer": "~6.0.1", "gulp": "^4.0.2", "gulp-gzip": "^1.4.2", "gzipper": "^4.3.0", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~6.0.0", "karma": "~6.0.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage-istanbul-reporter": "~3.0.3", "karma-jasmine": "~4.0.1", "karma-jasmine-html-reporter": "^1.5.4", "protractor": "~7.0.0", "ts-node": "~9.1.1", "tslint": "~6.1.3", "typescript": "^4.0.5", "webpack-bundle-analyzer": "^4.3.0" }, "browser": { "crypto": false } }
Dockerfile内容
# Stage 1: Build the Angular app FROM node:14.21.2 AS build # Set the working directory in the container WORKDIR /app # Copy the package.json and package-lock.json files to the container COPY package*.json ./ # Check npm version RUN npm -version # Change npm version RUN npm install -g npm@6.14.17 # Install Angular CLI globally RUN npm install -g @angular/cli@11.0.7 # Install application dependencies RUN npm install # Copy the application code to the container COPY . . # Build the Angular app RUN ng build --configuration production # Stage 2: Create a lightweight production image FROM nginx # Copy the built Angular app from the previous stage to the NGINX directory COPY --from=build /app/dist/* /usr/share/nginx/html/ # Expose the default NGINX port EXPOSE 80 # Start the NGINX server CMD ["nginx", "-g", "daemon off;"]
构建时的错误日志
DeprecationWarning: 'createObjectLiteralExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createArrayLiteralExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: '' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createBinaryExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createLiteral' has been deprecated since v4.0.0. Use factory.createStringLiteral, factory.createStringLiteralFromNode, factory.createNumericLiteral, factory.createBigIntLiteral, factory.createTrue, factory.createFalse, or the factory supplied by your transformation context instead. DeprecationWarning: 'createCallExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createNewExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createReturnStatement' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createBlock' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createParameterDeclaration' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createFunctionExpression' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. DeprecationWarning: 'createExpressionStatement' has been deprecated since v4.0.0. Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead. Error: Debug Failure. Unhandled SyntaxKind: Unknown. at pipelineEmitWithHintWorker (/app/node_modules/typescript/lib/typescript.js:114185:22) at pipelineEmitWithHint (/app/node_modules/typescript/lib/typescript.js:113716:17) at pipelineEmitWithComments (/app/node_modules/typescript/lib/typescript.js:117404:13) at pipelineEmit (/app/node_modules/typescript/lib/typescript.js:113656:13) at emit (/app/node_modules/typescript/lib/typescript.js:113629:13) at emitParameter (/app/node_modules/typescript/lib/typescript.js:114422:13) at pipelineEmitWithHintWorker (/app/node_modules/typescript/lib/typescript.js:113765:32) at pipelineEmitWithHint (/app/node_modules/typescript/lib/typescript.js:113716:17) at pipelineEmitWithComments (/app/node_modules/typescript/lib/typescript.js:117404:13) at pipelineEmit (/app/node_modules/typescript/lib/typescript.js:113656:13) An unhandled exception occurred: NGCC failed. See "/tmp/ng-hN7qYo/angular-errors.log" for further details. The command '/bin/sh -c ng build --configuration production' returned a non-zero code: 127
我已经核对过本地和DevOps构建环境里的Node(14.21.2)、npm(6.14.17)、Angular CLI(11.0.7)版本完全一致,本地构建镜像毫无问题,但DevOps里就是触发这些TypeScript弃用警告,最后NGCC直接失败,还出现了SyntaxKind: Unknown的错误。实在摸不着头脑,有没有朋友遇到过类似情况,或者能给点排查方向的?
备注:内容来源于stack exchange,提问作者Mushfiqur Rahman Koushiq
相关产品推荐
相关产品推荐

