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

Dev server: minimize the "Module not found" error during rebuilds #722

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

vmarta
Copy link
Contributor

@vmarta vmarta commented Sep 16, 2022

When developing our hooks library (commerce-sdk-react) and testing in the test-commerce project, we were seeing Module Not Found error pretty frequently. As a workaround, we had to restart our dev server. But doing so many times hurt our development flow.

NeoVim Terminal 2022-09-16 at 11 33 18

I found webpack to be too eager to rebuild the app you're working on, whenever one of our sdk packages is being rebuilt. We needed a way to tell webpack to wait a bit before doing its rebuild. This PR adds a new watch option in the webpack config.

Ticket: W-11767052

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

How to Test-Drive This PR

First of all, run the dev server in the test-commerce project, and then run a build watch in our hooks library:

npm ci # at the root of monorepo, to rebuild all the packages
cd packages/test-commerce-sdk-react/
npm start
# Then open up a new terminal window/tab
cd packages/commerce-sdk-react
npm run build:watch

Then in your code editor:

  1. Open up one of the files in the package commerce-sdk-react
  2. Do a save (yes, no need to write additional code), and that should trigger the build-watch to rebuild the hooks library
  3. Verify in your browser that the site is still working OK.

Some variations to try:

  • Do a save multiple times in a row ← to simulate developers who love to save their changes often
  • If you see the Module Not Found error (it still happens occasionally), see if you do another save, would that fix things?

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

I found webpack to be too eager to rebuild the app you're working on, whenever one of our sdk packages is built. We needed a way to tell webpack to wait a bit before doing its rebuild.
@@ -77,6 +77,9 @@ const baseConfig = (target) => {
class Builder {
constructor() {
this.config = {
watchOptions: {
aggregateTimeout: 1000
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vmarta vmarta marked this pull request as ready for review September 16, 2022 18:45
@vmarta vmarta requested a review from a team as a code owner September 16, 2022 18:45
@vmarta vmarta added the ready for review PR is ready to be reviewed label Sep 16, 2022
Copy link
Collaborator

@kevinxh kevinxh left a comment

Choose a reason for hiding this comment

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

Please also add changelog :)

@vmarta vmarta merged commit 76b83d4 into develop Sep 16, 2022
@vmarta vmarta deleted the webpack-rebuild-error branch September 16, 2022 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants