GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: add null check for module existence with helpful error message by samarthsinh2660 · Pull Request #20221 · webpack/webpack

Conversation

@samarthsinh2660

@samarthsinh2660 samarthsinh2660 commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

Adds a check before module execution to provide a helpful error message when a module ID is not found in __webpack_modules__, instead of the cryptic Cannot read properties of undefined (reading 'call') error.

Fixes #18021

Summary

When a module ID is missing from __webpack_modules__, the webpack runtime currently tries to execute it and crashes with:

TypeError: Cannot read properties of undefined (reading 'call')

This error originates from the generated runtime in JavascriptModulesPlugin and does not clearly tell users that the actual problem is a missing/unloaded module.

This PR adds a defensive check before executing the module factory:

  • If __webpack_modules__[moduleId] is undefined, we now throw a descriptive Error explaining that the module with the given ID cannot be found and may not be loaded or was removed.
  • This turns a low-level TypeError into a clear, actionable error message, improving the UX when module loading goes wrong (e.g. dynamic imports, federation, or other advanced setups).

What kind of change does this PR introduce?

  • Bugfix / UX improvement (better runtime error handling)
  • New feature
  • Refactoring
  • Build related change
  • Other

Did you add tests for your changes?

  • Yes
  • No

This change is a small defensive check inside the runtime path and is mainly focused on improving the error message, not changing the control flow. The existing runtime/missing-module tests already cover the behavior that an Error is thrown when a module is missing; this PR only makes the message clearer.

I am happy to add a dedicated test if maintainers can suggest the preferred place and pattern (e.g. extending test/cases/runtime/error-handling or one of the missing-module-* runtime cases) to assert the new message.

Does this PR introduce a breaking change?

  • No
  • Yes

The behavior (throwing an error when a module is missing) stays the same; only the error message becomes more descriptive.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

No documentation updates are required. This change only improves the runtime error message surfaced to users when a module cannot be found.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@changeset-bot

changeset-bot Bot commented Dec 10, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 186250b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alexander-akait
alexander-akait reviewed Dec 10, 2025
View reviewed changes
Comment thread lib/javascript/JavascriptModulesPlugin.js Outdated
Template.indent([
"throw new Error('Cannot find module with id \"' + moduleId + '\". The module might not be loaded or was removed.');"
]),
"}",

@alexander-akait alexander-akait Dec 10, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It should be only for development mode

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@samarthsinh2660 samarthsinh2660 Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Development-only error:
Wrapped the helpful error in a check using outputOptions.pathinfo, which is only true in development (see lib/config/defaults.js, where output.output.pathinfo is set based on development). So the error is thrown only in dev builds.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
alexander-akait
alexander-akait reviewed Dec 10, 2025
View reviewed changes
Comment thread lib/javascript/JavascriptModulesPlugin.js Outdated
return `__webpack_modules__[${moduleIdExpr}](${args.join(",")});`;
return `__webpack_modules__[${moduleIdExpr}](${args.join(
","
)});`;

@alexander-akait alexander-akait Dec 10, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Remove unrelated changes

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@samarthsinh2660 samarthsinh2660 Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The webpack_modules${moduleIdExpr}; calls are unchanged now. The only change in
JavascriptModulesPlugin.js
is the new development-only check right after the cache lookup and before creating the module.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
alexander-akait
alexander-akait requested changes Dec 10, 2025
View reviewed changes

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Also please add a test case

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

samarthsinh2660 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
xiaoxiaojx
xiaoxiaojx reviewed Dec 11, 2025
View reviewed changes
Comment thread lib/javascript/JavascriptModulesPlugin.js Outdated
"// Check if module exists (development only)",
"if (__webpack_modules__[moduleId] === undefined) {",
Template.indent([
"throw new Error('Cannot find module with id \"' + moduleId + '\". The module might not be loaded or was removed.');"

@xiaoxiaojx xiaoxiaojx Dec 11, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This seems good — we can make the error message fully match Node.js and set the error code to MODULE_NOT_FOUND.
telegram-cloud-photo-size-5-6183626581591395300-y

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@samarthsinh2660 samarthsinh2660 Dec 11, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Updated! The error now matches Node.js format:

Message: Cannot find module ''
Error code: MODULE_NOT_FOUND
Also rebased on latest main.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xiaoxiaojx reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
samarthsinh2660 added 3 commits December 11, 2025 11:16
@samarthsinh2660
fix: add null check for module existence with helpful error message
8baeed2
Adds a check before module execution to provide a helpful error message when a module ID is not found in __webpack_modules__, instead of the cryptic 'Cannot read properties of undefined (reading call)' error.

Fixes webpack#18021
@samarthsinh2660
fix: add null check for module existence with helpful error message
12b19af
@samarthsinh2660
fix: match Node.js error format with MODULE_NOT_FOUND code
a203dbd
@samarthsinh2660
samarthsinh2660 force-pushed the fix/improve-module-not-found-error branch from 7e95e7f to a203dbd Compare December 11, 2025 05:47
@samarthsinh2660
samarthsinh2660 requested review from alexander-akait and xiaoxiaojx December 11, 2025 06:21
@codspeed

codspeed Bot commented Dec 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #20221 will not alter performance

Comparing samarthsinh2660:fix/improve-module-not-found-error (186250b) with main (0c52a8f)

Summary

✅ 72 untouched

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alexander-akait
alexander-akait reviewed Dec 11, 2025
View reviewed changes

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good, let's fix tests and we can merge, thanks

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

samarthsinh2660 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@samarthsinh2660
samarthsinh2660 force-pushed the fix/improve-module-not-found-error branch from 57b424b to dd198d7 Compare December 11, 2025 14:45
@samarthsinh2660
samarthsinh2660 requested a review from alexander-akait December 11, 2025 15:02
@alexander-akait

alexander-akait commented Dec 11, 2025

Copy link
Copy Markdown
Member

Please update snapshots for cached too

samarthsinh2660 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samarthsinh2660
samarthsinh2660 force-pushed the fix/improve-module-not-found-error branch from dd198d7 to 4455b9f Compare December 11, 2025 16:01
@alexander-akait

alexander-akait commented Dec 11, 2025

Copy link
Copy Markdown
Member

Just run yarn test:base ./test/ConfigTestCases.basictest.js -u --no-verbose and yarn test:base ./test/ConfigCacheTestCases.longtest.js -u --no-verbose

samarthsinh2660 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@samarthsinh2660
test: update snapshots for module not found error
ac878f2
@samarthsinh2660
samarthsinh2660 force-pushed the fix/improve-module-not-found-error branch from 4455b9f to ac878f2 Compare December 11, 2025 16:29
alexander-akait
alexander-akait approved these changes Dec 11, 2025
View reviewed changes
@alexander-akait
Create cuddly-cameras-cross.md
186250b
@alexander-akait
alexander-akait merged commit 22c48fb into webpack:main Dec 11, 2025
@alexander-akait

alexander-akait commented Dec 11, 2025

Copy link
Copy Markdown
Member

Thanks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (22c48fb).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@22c48fb
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@22c48fb
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@22c48fb
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lukesandberg lukesandberg mentioned this pull request Feb 19, 2026
#20221 module existence check breaks interceptModuleExecution recovery for missing modules #20475
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alexander-akait alexander-akait alexander-akait approved these changes
@xiaoxiaojx xiaoxiaojx Awaiting requested review from xiaoxiaojx

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add null check to avoid TypeError: Cannot read properties of undefined (reading 'call')

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@samarthsinh2660 @alexander-akait @xiaoxiaojx
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.