GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: add null check for module existence with helpful error message by samarthsinh2660 · Pull Request #20221 · webpack/webpack Conversation
Contributor
Adds a check before module execution to provide a helpful error message when a module ID is not found in Fixes #18021 Summary When a module ID is missing from
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:
What kind of change does this PR introduce?
Did you add tests for your changes?
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 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 Does this PR introduce a breaking change?
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
|
There was an error while loading. Please reload this page.
🦋 Changeset detectedLatest commit: 186250b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Template.indent([ | ||
| "throw new Error('Cannot find module with id \"' + moduleId + '\". The module might not be loaded or was removed.');" | ||
| ]), | ||
| "}", |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| return `__webpack_modules__[${moduleIdExpr}](${args.join(",")});`; | ||
| return `__webpack_modules__[${moduleIdExpr}](${args.join( | ||
| "," | ||
| )});`; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Remove unrelated changes
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| "// 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.');" |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
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
7e95e7f to
a203dbd
Compare
There was an error while loading. Please reload this page.
CodSpeed Performance ReportMerging #20221 will not alter performanceComparing Summary
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
57b424b to
dd198d7
Compare
|
Please update snapshots for cached too |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
dd198d7 to
4455b9f
Compare
|
Just run |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
4455b9f to
ac878f2
Compare
|
Thanks |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is packaged and the instant preview is available (22c48fb). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@22c48fb
yarn add -D webpack@https://pkg.pr.new/webpack@22c48fb
pnpm add -D webpack@https://pkg.pr.new/webpack@22c48fb |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Add null check to avoidTypeError: Cannot read properties of undefined (reading 'call')
There was an error while loading. Please reload this page.