Skip to content

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

@fregante

Description

@fregante

Feature request

Note that this is not a bug report, this is a UX improvement ticket. It won't actually solve the underlying issue but it might help webpack users understand it better.

What is the expected behavior?

Occasionally webpack fails to properly load modules and it fails on this line, causing:

And others like it: https://github.com/webpack/webpack/issues?q=is:issue+sort%253Aupdated-desc+%2522Cannot+read+properties+of+undefined%2522+in%253Atitle+is%253Aclosed++call

What is motivation or use case for adding/changing the behavior?

The error is in webpack's own code and it's far removed from the cause.

How should this be implemented in your opinion?

Catching the error and rewording it will help people find a solution.

A better error would look like this, including as much information as possible regarding its context

"The module sugar/free.js could not be loaded from './wood-cake.js' etc"

Are you willing to work on this yourself?

If the fix looks like this yes:

+ if (typeof __webpack_modules__[moduleId] !== 'function') {
+ 	throw new Error(`The module xyz could not be loaded`)
+ }
  __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Priority - Low

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions