在AWS中用CodeBuild构建Angular PlotlyJS项目时CI/CD报错求助
解决AWS CodeBuild执行ng build时Angular PlotlyJS依赖错误
先修复buildspec.yml的格式问题
你提供的buildspec.yml存在缩进错误,这会导致CodeBuild解析配置失败,先修正为正确格式:
version: 0.2 env: variables: CACHE_CONTROL: "86400" BUILD_FOLDER: "dist" phases: install: runtime-versions: nodejs: 16 commands: - echo Installing source NPM dependencies... - npm install - npm install -g @angular/cli build: commands: - echo Build started - ng build artifacts: files: - '**/*' base-directory: 'dist*' discard-paths: yes
针对PlotlyJS依赖错误的解决方案
确保依赖完整安装
检查项目package.json中是否已添加angular-plotly.js或plotly.js依赖,且版本与当前Angular版本兼容。CodeBuild的install阶段用npm install即可,不要加--production参数,避免跳过开发依赖。统一Angular CLI版本
本地开发用的CLI版本可能和CodeBuild全局安装的不一致,建议把build阶段的ng build改成npx ng build,这样会使用项目本地安装的CLI,避免版本冲突。检查PlotlyJS的Angular配置
如果项目需要全局引入PlotlyJS,要在angular.json的architect.build.options.scripts里添加对应的脚本路径:"scripts": [ "node_modules/plotly.js/dist/plotly.min.js" ]确认这个配置已经提交到代码仓库,不然CodeBuild环境里会缺少全局脚本引用。
内容的提问来源于stack exchange,提问作者Dev Team
相关产品推荐
相关产品推荐

