Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(npm/webpack-preprocessor): WIP support webpack 5 alongside webpack 4 #16493

Merged
merged 3 commits into from
May 13, 2021

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented May 13, 2021

User facing changelog

Experimental support for webpack v5 alongside webpack v4 in @cypress/webpack-preprocessor.

Additional details

Initially, I tried to make a next version of @cypress/webpack-preprocessor that would support Webpack 5. I then updated all the dependencies in the monorepo to webpack 5, and tried to get everything to pass.

I got everything to compile. I got most of the tests to pass, but not all. A lot of our dependencies (or their dependencies, etc) are coupled to webpack 4.

The main problem is that webpack 5 deprecated auto polyfills of node modules. I tried a few things, like using a polyfill, providing custom implementations. It got pretty close to passing (around 95% of specs passing in packages).

There are some hard blockers:

  • some examples in npm/react/examples and npm/webpack-preprocessor/examples can never pass. Specifically, ones using tools like CRA, which have not yet upgraded to Webpack 5.
  • ideally, we should upgrade Cypress to use Webpack 5, too.

For now, I think we should try and support webpack 4 an 5 alongside each other, like I've done here. The next version of @cypress/webpack-preprocessor, which will be v6, will drop support for Webpack 4. At this point we should transition Cypress to use webpack 5 internally, too. It's a big change, so it might take some time. This is another compelling reason to do this incremental update.

How has the user experience changed?

  • can use with webpack v5
  • users will need to deal with webpack 5 breaking changes, mainly the deprecation of auto polyfilled core node modules. They could use this polyfill for general use cases.

PR Tasks

  • Have tests been added/updated?
  • Has the original issue or this PR been tagged with a release in ZenHub?
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 13, 2021

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented May 13, 2021



Test summary

4061 0 53 2Flakiness 0


Run details

Project cypress
Status Passed
Commit a96d11e
Started May 13, 2021 3:12 PM
Ended May 13, 2021 3:25 PM
Duration 12:05 💡
OS Linux Debian - 10.8
Browser Firefox 77

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990 lmiller1990 mentioned this pull request May 13, 2021
@lmiller1990 lmiller1990 marked this pull request as ready for review May 13, 2021 14:19
Copy link
Contributor

@agg23 agg23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprising that there's so little to be done. Doesn't seem like it will cause adverse effects.

@@ -330,8 +330,6 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
// when we should watch, we hook into the 'compile' hook so we know when
// to rerun the tests
if (file.shouldWatch) {
debug('watching')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol what's wrong with this debug message?

npm/webpack-preprocessor/index.ts Show resolved Hide resolved
@agg23
Copy link
Contributor

agg23 commented May 13, 2021

Possibly related:

Why do we always set up the Webpack 4 hook, even with Webpack 5, in webpack-dev-server?

if ('NormalModule' in webpack) {
// @ts-ignore
webpack.NormalModule.getCompilationHooks(compilation).loader.tap(
'CypressCTOptionsPlugin',
this.pluginFunc,
)
return
}
// Webpack 4
compilation.hooks.normalModuleLoader.tap(
'CypressCTOptionsPlugin',
this.pluginFunc,
)
};

Copy link
Contributor

@elevatebart elevatebart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should bring back the debug message. But this looks good

@lmiller1990 lmiller1990 merged commit d37fa84 into develop May 13, 2021
lmiller1990 added a commit that referenced this pull request May 13, 2021
…ck 4 (#16493)

* feat: support webpack 5 alongside webpack 5

* revert code
lmiller1990 added a commit that referenced this pull request May 13, 2021
…ck 4 (#16493) (#16504)

* feat: support webpack 5 alongside webpack 5

* revert code
@WIStudent
Copy link

I think the peerDependeny in package.json also needs to be updated to allow webpack 4 and 5. Otherwise npm@7 will throw this:

$ npm install --save-dev @cypress/webpack-preprocessor
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-project@1.0.0
npm ERR! Found: webpack@5.39.0
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"^5.39.0" from the root project
npm ERR!   peer webpack@">=2" from babel-loader@8.2.2
npm ERR!   node_modules/babel-loader
npm ERR!     dev babel-loader@"^8.2.2" from the root project
npm ERR!     peer babel-loader@"^8.0.2" from @cypress/webpack-preprocessor@5.9.0
npm ERR!     node_modules/@cypress/webpack-preprocessor
npm ERR!       dev @cypress/webpack-preprocessor@"*" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.18.1" from @cypress/webpack-preprocessor@5.9.0
npm ERR! node_modules/@cypress/webpack-preprocessor
npm ERR!   dev @cypress/webpack-preprocessor@"*" from the root project

@elevatebart
Copy link
Contributor

@WIStudent you are absolutely right.

Can you create an issue so that we don't forget to fix it?

Thank you in advance.

@emilyrohrbough emilyrohrbough deleted the support-webpack-5-in-preprocessor branch August 1, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Webpack 5 support
4 participants