Skip to content

TypeError when running component tests with Next.js 16 and Webpack #32839

@KenTandrian

Description

@KenTandrian

Current behavior

Cypress fails to load the configuration file and throws the following error:

TypeError: webpackModule.init is not a function
    at sourceNextWebpack (/Users/me/Library/Caches/Cypress/15.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/helpers/nextHandler.js:308:19)
    at sourceNextWebpackDeps (/Users/me/Library/Caches/Cypress/15.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/helpers/nextHandler.js:268:21)
    at nextHandler (/Users/me/Library/Caches/Cypress/15.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/helpers/nextHandler.js:18:74)
    at async getPreset (/Users/me/Library/Caches/Cypress/15.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/devServer.js:60:20)
    at async devServer.create (/Users/me/Library/Caches/Cypress/15.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/devServer.js:79:61)
    at async /Users/me/Library/Caches/Cypress/15.5.0/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-dev-server/dist/devServer.js:22:24

Desired behavior

Cypress should successfully load the configuration file and run the component tests without errors.

Test code to reproduce

https://github.com/KenTandrian/cypress-nextjs-16-webpack

Reproduction Steps:

  1. Create a Next.js project (version 16.0.0).
  2. Install Cypress (version 15.5.0) with component testing support.
  3. Configure Cypress to use the Next.js framework and webpack bundler in cypress.config.ts.
  4. Attempt to run component tests using the command yarn cypress run --component.

Cypress Version

15.5.0

Debug Logs

N/A -- it fails before running the test.

Other

The issue started occurring after upgrading to Next.js version 16. This suggests a potential incompatibility or breaking change introduced in Next.js 16.

I believe the error stems from the Cypress code still calling webpackModule.init here:

webpackModule.init(webpack5)

This function no longer exists in the newer node_modules/next/dist/compiled/webpack/webpack.js file in Next.js 16.

Previous:
https://github.com/vercel/next.js/blob/de19200deb33869fc691b43e68aef76493d79fa1/packages/next/src/compiled/webpack/webpack.js#L5

Now:
https://github.com/vercel/next.js/blob/d27f18f390ce2ac5728fb902a004381d876e85bd/packages/next/src/compiled/webpack/webpack.js#L5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions