Cypress Rspack Dev Server
cypress-rspack-dev-server is a Cypress component testing dev server that integrates with Rspack, providing a fast and efficient build toolchain for testing front-end components. It allows developers to leverage Rspack's performance benefits within their Cypress test environment, handling asset compilation and serving for component tests. The current stable version is 1.1.2, though release candidates for 2.0.0 supporting Rspack 2 are actively being developed. The package's release cadence appears to align with major updates to Rspack and Cypress itself, indicating a responsive maintenance schedule rather than fixed intervals. Its primary differentiator is the direct integration with Rspack, offering an alternative to webpack-based dev servers for users already committed to the Rspack ecosystem.
Common errors
-
Error: Cannot find module '@cypress/rspack-dev-server'
cause The package is not installed or incorrectly referenced in `cypress.config.ts`.fixEnsure the package is installed: `npm install --save-dev @cypress/rspack-dev-server` or `yarn add -D @cypress/rspack-dev-server`. Verify the import path in your Cypress configuration. -
TypeError: Cannot read properties of undefined (reading 'rspackConfig')
cause The `rspackConfig` property is missing or malformed in the `devServer` options passed to `createRspackDevServer`.fixIn your `cypress.config.ts`, ensure that `createRspackDevServer` is called with an object containing at least `framework`, `bundler`, and a valid `rspackConfig` property, e.g., `{ framework: 'react', bundler: 'rspack', rspackConfig }`. -
Error: Rspack compilation failed: Module not found: Error: Can't resolve './src/App'
cause Your Rspack configuration's `resolve` or `module.rules` settings are not correctly configured to find your component files or their dependencies.fixReview the `rspackConfig` object in your `cypress.config.ts`. Check `resolve.extensions` to ensure it includes all file types your components use (e.g., '.js', '.jsx', '.ts', '.tsx') and `resolve.alias` if you use path aliases. Verify `module.rules` for correct loaders.
Warnings
- breaking Version 2.0.0-rc.1 (and subsequent RCs) introduces an upgrade to Rspack 2. This is a significant breaking change as Rspack 2 includes its own breaking changes and potentially requires adjustments to your Rspack configuration.
- gotcha When using interactive mode (e.g., `cypress open`), an issue was reported where `contenthash` in output filenames could lead to 404 errors. This was fixed in 1.1.2.
- gotcha Incorrect resolution of component index files when the Rspack configuration is located in a subdirectory was an issue in earlier versions.
- breaking Cypress itself has undergone significant changes in how dev servers are configured, particularly with the introduction of new `devServer` options in `cypress.config.ts`. Older configurations might not be compatible.
Install
-
npm install cypress-rspack-dev-server -
yarn add cypress-rspack-dev-server -
pnpm add cypress-rspack-dev-server
Imports
- createRspackDevServer
const createRspackDevServer = require('@cypress/rspack-dev-server').createRspackDevServerimport { createRspackDevServer } from '@cypress/rspack-dev-server' - RspackConfig
import type { RspackOptions } from '@rspack/core'; import type { CypressRspackDevServerConfig } from '@cypress/rspack-dev-server'; - devServer
import { defineConfig } from 'cypress'; import { createRspackDevServer } from '@cypress/rspack-dev-server'; export default defineConfig({ component: { devServer: createRspackDevServer, }, });
Quickstart
import { defineConfig } from 'cypress';
import { createRspackDevServer } from '@cypress/rspack-dev-server';
import { Configuration as RspackConfiguration } from '@rspack/core';
const rspackConfig: RspackConfiguration = {
// Your Rspack configuration for component testing
mode: 'development',
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx'],
},
module: {
rules: [
{
test: /\.(js|ts|jsx|tsx)$/,
exclude: /node_modules/,
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
jsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
],
},
// Add any other Rspack specific configurations here
};
export default defineConfig({
component: {
devServer: {
framework: 'react',
bundler: 'rspack',
rspackConfig,
},
devServer: createRspackDevServer,
specPattern: '**/*.cy.{js,jsx,ts,tsx}',
},
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});