You need to enable JavaScript to run this app. Bitbucket Pipeline运行npm命令报错Playwright Chromium缺失
优惠活动
大模型
产品
解决方案
定价
更多

Bitbucket Pipeline运行npm命令报错Playwright Chromium缺失

解决方案

故障根因

  • Bitbucket Pipelines 的每个step运行在独立容器中,前序step写入的非缓存目录内容不会传递到后续step
  • 默认的node缓存仅覆盖node_modules目录,Playwright 依赖的浏览器二进制默认存储在/root/.cache/ms-playwright路径,不在默认缓存范围内,就算node_modules缓存正常,浏览器文件依然会丢失

修复方案

推荐使用单step+自定义缓存的配置,既保证环境一致性,又能通过缓存加快后续运行速度:

image: node:14-stretch

pipelines:
  default:
    - step:
        name: 执行Playwright测试
        caches:
          - node
          - playwright-cache
        script:
          # 安装系统依赖
          - apt update && apt install -y curl sudo git wget unzip xvfb libnss3 libgtk-3-0 libasound2 fonts-liberation
          # 安装项目依赖
          - npm install
          # 主动安装Playwright对应版本的Chromium,避免缺失
          - npx playwright install chromium
          # 运行测试
          - npm run execute:test

# 自定义Playwright浏览器缓存路径
definitions:
  caches:
    playwright-cache: /root/.cache/ms-playwright

可选调整(保留多step结构)

如果需要拆分step,需要在安装依赖和执行测试的step都添加playwright-cache缓存配置,同时在安装依赖的step主动执行npx playwright install chromium命令。

注意事项

  • 如果测试需要用到Firefox、Webkit等其他浏览器,可将npx playwright install chromium修改为npx playwright install安装全量浏览器
  • 升级Playwright版本后,需要进入Bitbucket仓库的流水线设置页面清除现有缓存,避免新旧版本浏览器二进制冲突

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.15 20:06:00