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

Cypress从9.5.4升级到10.11.0后Webpack编译错误求助

Cypress 9.5.4 迁移至 10.11.0 后 Webpack 编译错误排查求助

我将Cypress从9.5.4版本迁移至10.11.0版本后,出现了大量此前未遇到的Webpack编译错误。部分错误已通过@cypress/webpack-preprocessor解决,但仍有部分无法处理,恳请协助解决截图中的问题。

相关配置代码如下:

const findWebpack = require('find-webpack');
const injectDevServer = require('@cypress/react/plugins/react-scripts');
const webpackPreprocessor = require('@cypress/webpack-preprocessor');

/**
 * @type {Cypress.PluginConfig}
 */
module.exports = (on, config) => {
  // const webpack = require('./webpack.config.js');
  // find the Webpack config used by react-scripts
  const webpackOptions = findWebpack.getWebpackOptions();

  if (!webpackOptions) {
    throw new Error('Could not find Webpack in this project 😢');
  }

  // if we just pass webpackOptions to the preprocessor
  // it won't work - because react-scripts by default
  // includes plugins that split specs into chunks, etc.
  // https://github.com/cypress-io/cypress-webpack-preprocessor/issues/31

  // solution 1
  // blunt: delete entire optimization object
  // delete webpackOptions.optimization

  // solution 2
  // use a module that carefully removes only plugins
  // that we found to be breaking the bundling
  // https://github.com/bahmutov/find-webpack
  const cleanOptions = {
    reactScripts: true,
  };

  findWebpack.cleanForCypress(cleanOptions, webpackOptions);

  const options = {
    webpackOptions,
    watchOptions: {},
  };

  injectDevServer(on, config);
  on('file:preprocessor', webpackPreprocessor(options));
  return config;
};

Webpack编译错误截图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 01:31:21