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

Cypress运行遇ENOENT错误及依赖解析失败问题求助

解决Cypress GUI/CLI运行测试的依赖解析与文件缺失问题

问题现象

  • 通过Cypress GUI运行测试时,出现文件不存在错误:
    Error: ENOENT: no such file or directory, stat '/home/user/.config/Cypress/cy/production/projects/testProject-ba4506b83588731a9b974658caac8b40/bundles/cypress/e2e/01-test-details.feature'
    
    且指定路径下不存在bundles文件夹
  • 通过CLI运行测试时,构建失败并提示14个错误,核心为无法解析@badeball/cypress-cucumber-preprocessor、moment等依赖,已确认相关依赖已安装

环境信息:Node v21.2.0、Ubuntu 22.04.3 LTS、Yarn 1.22.19、Cypress ^13.5.1


解决方案

1. 清理Cypress缓存

Cypress缓存目录可能存在损坏的生成文件,执行以下命令清空缓存,让Cypress重新生成必要的bundles文件:

npx cypress cache clear

之后重新启动Cypress GUI或执行CLI测试命令。

2. 重新安装并校验依赖

即使已确认依赖安装,仍可能存在缓存或链接异常,执行以下步骤重置依赖:

# 清理Yarn缓存
yarn cache clean
# 删除现有依赖包和锁文件
rm -rf node_modules
rm yarn.lock
# 重新安装依赖
yarn install

安装完成后,校验依赖是否正确安装:

yarn list @badeball/cypress-cucumber-preprocessor moment

确保输出中能看到对应依赖的版本信息,无缺失或报错。

3. 检查Cypress配置正确性

确认cypress.config.js(或cypress.config.ts)中@badeball/cypress-cucumber-preprocessor的配置无误,示例配置如下:

const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const addCucumberPreprocessorPlugin = require("@badeball/cypress-cucumber-preprocessor").addCucumberPreprocessorPlugin;
const createEsbuildPlugin = require("@badeball/cypress-cucumber-preprocessor/esbuild").createEsbuildPlugin;

module.exports = defineConfig({
  e2e: {
    async setupNodeEvents(on, config) {
      const bundler = createBundler({
        plugins: [createEsbuildPlugin(config)],
      });
      on("file:preprocessor", bundler);
      await addCucumberPreprocessorPlugin(on, config);
      return config;
    },
    // 确保specPattern指向正确的feature文件路径
    specPattern: "cypress/e2e/**/*.feature",
  },
});

重点检查specPattern是否匹配本地feature文件的实际路径,以及预处理器的配置是否完整。

4. 验证本地文件路径

确认项目中cypress/e2e/01-test-details.feature文件确实存在,注意Linux系统区分文件名大小写,检查路径拼写是否完全一致。

5. 切换Node LTS版本

Node v21为非LTS版本,可能与Cypress或部分依赖存在兼容性问题,建议切换到LTS版本(如Node v20.x),可通过nvm管理版本:

# 安装Node v20 LTS
nvm install 20
# 切换到该版本
nvm use 20

切换后重新执行依赖安装和测试运行。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 03:28:16