You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

BitBucket Pipeline未正确缓存Angular项目node_modules问题求助

解决BitBucket Pipeline中Angular node_modules缓存失效的问题

你遇到的核心问题是缓存路径配置不对——BitBucket Pipeline找不到你要缓存的node_modules目录,自然没法复用缓存内容啦。咱们一步步来修正:

1. 修正缓存路径定义

你当前把缓存路径写成了/ui/node_modules,这是容器根目录下的路径,但BitBucket会把你的仓库克隆到$BITBUCKET_CLONE_DIR目录(容器默认工作目录就是这个路径),实际的node_modules是在仓库根目录的ui文件夹下。

直接用相对路径定义缓存更稳妥,修改definitions里的缓存配置:

definitions:
  caches:
    angular-node: ui/node_modules

2. 优化npm install命令(可选但推荐)

为了让npm优先读取缓存的依赖,减少重复下载时间,你可以给npm install加上--prefer-offline参数:

script:
  - cd ui
  - npm install --prefer-offline
  - ng test --watch=false

3. 完整修正后的配置

把这些调整整合起来,最终的Pipeline配置如下:

image: trion/ng-cli-karma
pipelines:
  default:
    - step:
        caches:
          - angular-node
        script:
          - cd ui
          - npm install --prefer-offline
          - ng test --watch=false
definitions:
  caches:
    angular-node: ui/node_modules

这样调整后,下次Pipeline运行时,BitBucket就能正确识别并缓存ui/node_modules目录,后续构建会直接复用缓存的依赖包,不用再重新下载全部内容了。

内容的提问来源于stack exchange,提问作者infojolt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:13:38