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

运行Feature文件报错:无法遍历依赖图,找不到指定Cypress Cucumber预处理器模块

解决Can't find module '@badeball/cypress-cucumber-preprocessor/steps'错误

修复步骤

1. 确认依赖包安装状态

先确保@badeball/cypress-cucumber-preprocessor已正确安装,执行以下命令:

npm install @badeball/cypress-cucumber-preprocessor --save-dev
# 若用yarn则执行
yarn add @badeball/cypress-cucumber-preprocessor --dev

如果已经安装过,尝试清理依赖后重新安装:

rm -rf node_modules package-lock.json
npm install

2. 检查Cypress配置文件

验证cypress.config.js(或cypress.config.ts)中的步骤定义路径配置是否正确,确保stepDefinitions指向你存放步骤文件的目录。示例配置:

import { defineConfig } from "cypress";
import preprocessor from "@badeball/cypress-cucumber-preprocessor";
import browserify from "@badeball/cypress-cucumber-preprocessor/browserify";

async function setupNodeEvents(on, config) {
  await preprocessor.addCucumberPreprocessorPlugin(on, config);
  on("file:preprocessor", browserify(config));
  return config;
}

export default defineConfig({
  e2e: {
    specPattern: "cypress/e2e/**/*.feature",
    stepDefinitions: "cypress/e2e/**/*.js", // 路径需匹配你的实际文件位置
    setupNodeEvents,
  },
});

3. 验证步骤定义文件结构

确保步骤定义文件(.js/.ts)放在配置指定的路径下,且文件中正确导入并导出步骤,示例:

import { Given, When, Then } from "@badeball/cypress-cucumber-preprocessor";

Given("我打开首页", () => {
  cy.visit("/");
});

4. 检查版本兼容性

确认@badeball/cypress-cucumber-preprocessor版本与你使用的Cypress版本兼容,可参考官方文档的版本匹配说明,避免因版本不兼容导致模块查找失败。

相关截图

错误提示截图
Cypress配置文件截图
项目目录结构截图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 10:54:55