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

安装playwright包后无法运行npx playwright test --ui的问题求助

解决Playwright Test提示未安装@playwright/test的问题

可能的原因及解决步骤

  • 确认依赖是否正确安装
    先打开项目的package.json,检查devDependencies里是否存在@playwright/test。如果没有,重新执行安装命令:

    npm install -D @playwright/test
    

    若已存在但仍报错,删除本地依赖缓存后重装:

    rm -rf node_modules package-lock.json
    npm install
    
  • 直接调用本地包命令
    有时候npx会优先调用全局包,导致无法识别本地安装的@playwright/test。可以直接指定包名执行:

    npx @playwright/test test --ui
    

    或者在package.json中添加脚本:

    "scripts": {
      "test:e2e": "playwright test --ui"
    }
    

    然后通过npm脚本启动:

    npm run test:e2e
    
  • 排查全局包冲突
    若之前全局安装过playwright或@playwright/test,可能会干扰本地依赖。先查看全局安装的包:

    npm list -g --depth=0
    

    如果有相关全局包,建议卸载,仅保留项目本地依赖:

    npm uninstall -g playwright @playwright/test
    
  • 检查Node.js版本兼容性
    Playwright对Node.js版本有要求(建议v16及以上),执行node -v查看版本,不符合则升级Node.js。

关于两个包共存的说明

playwright和@playwright/test完全可以共存:

  • playwright提供chromium等浏览器驱动及基础API
  • @playwright/test是基于前者的测试框架,提供测试运行、断言、报告等功能
    实际上安装@playwright/test时会自动关联安装对应版本的playwright,除非你需要在非测试场景单独调用浏览器API,否则无需单独安装playwright。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 08:48:26