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

在BrowserStack仪表板集成Cypress时遇配置文件无效及模块缺失错误

在BrowserStack中集成Cypress时遇到"Cannot find module 'cypress'"错误

尝试在BrowserStack仪表板集成Cypress时,提示配置文件.\cypress.config.js无效,抛出"Cannot find module 'cypress'"错误,具体错误信息如下:

Error: Cannot find module 'cypress'
Require stack:


- .\cypress.config.js
- \cypress_package\12.9.0\win32\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_require_async_child.js
- \cypress_package\12.9.0\win32\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\require_async_child.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (.\cypress.config.js:1:26)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at loadFile (\cypress_package\12.9.0\win32\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_require_async_child.js:89:14)
    at EventEmitter.<anonymous> (\cypress_package\12.9.0\win32\Cypress\resources\app\node_modules\@packages\server\lib\plugins\child\run_require_async_child.js:116:38)
    at EventEmitter.emit (events.js:400:28)
    at process.<anonymous> (\cypress_package\12.9.0\win32\Cypress\resources\app\node_modules\@packages\server\lib\plugins\util.js:33:22)
    at process.emit (events.js:400:28)

cypress run process exited with code 1
cypress run failed, exiting with code: 1

我的browserstack.json配置内容如下:

{
    "auth": {
        "username": "ra!!!!s_u48vKc",
        "access_key": "SAkGQf!!!!!yeh2g"
    },
    "browsers": [
        {
            "browser": "chrome",
            "os": "Windows 10",
            "versions": [
                "latest",
                "latest-1"
            ]
        },
        {
            "browser": "firefox",
            "os": "Windows 10",
            "versions": [
                "latest",
                "latest-1"
            ]
        }
    ],
    "run_settings": {
        "cypress_config_file": "./cypress.config.js",
        "project_name": "Project1",
        "build_name": "RadwaBuild1",
        "parallels": "2",
        "spec_timeout": 10

    },
    "npm_dependencies": {
        "npm-package-you-need-to-run-tests-1": "^1.2.1",
        "npm-package-you-need-to-run-tests-2": "^7.1.6-beta.13"
      }
    }

执行的运行命令为:

browserstack-cypress run --sync --cypress-config-file C:\Users\ZZ00VO865\Desktop\CypressFrameworks\Project1\cypress.config.js

解决方案

  • 安装匹配版本的Cypress依赖:在项目根目录执行npm install cypress@12.9.0 --save-dev,确保本地项目依赖中包含对应版本的Cypress,同时检查package.json中是否已添加该依赖。
  • 修正BrowserStack依赖配置:修改browserstack.json里的npm_dependencies,替换占位包为实际需要的依赖,至少添加"cypress": "^12.9.0",保证云端环境能正确安装Cypress。
  • 校验配置文件路径与语法:确认命令行指定的绝对路径和browserstack.json中的相对路径指向同一个有效文件,同时检查cypress.config.js开头的require('cypress')语句无拼写错误。
  • 清理缓存后重试:执行npm cache clean --force清理npm缓存,重新安装依赖后再运行测试命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 18:47:01