Skip to content

[#2387] Uncaught TypeError: Cannot read property 'hot' of undefined#5498

Closed
Kamilius wants to merge 1 commit intowebpack:masterfrom
Kamilius:master
Closed

[#2387] Uncaught TypeError: Cannot read property 'hot' of undefined#5498
Kamilius wants to merge 1 commit intowebpack:masterfrom
Kamilius:master

Conversation

@Kamilius
Copy link
Copy Markdown

What kind of change does this PR introduce?
bugfix

Did you add tests for your changes?
No, as it is covered by already existing tests

If relevant, link to documentation update:
N/A

Summary
PR is solving a following reported issue "Uncaught TypeError: Cannot read property 'hot' of undefined" (#2387).
While one of installed modules inside a moduleOutdatedDependencies is undefined, it was crashing whole hot module replacement and was breaking an existing CSS for a given chunk.
Wrapping possible error into a try/catch block - totally solved problem, and being tested by me on real project for a last week.

Does this PR introduce a breaking change?
No

Other information
N/A

@webpack-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@wmertens
Copy link
Copy Markdown
Contributor

I just experienced this as well, and the reason is that it is trying to look up a dependency in the entry chunk.

So I think that instead of try-catch, you should just check if module is defined, and if not, print an error like "Cannot find module with id x"

However, I don't understand why it is trying to replace a module that is part of a chunk instead of replacing the chunk?

here's an inspection of the state at the moment it crashes. The relevant code is

/******/ 		var error = null;
/******/ 		for(moduleId in outdatedDependencies) {
/******/ 			if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
/******/ 				module = installedModules[moduleId];
/******/ 				moduleOutdatedDependencies = outdatedDependencies[moduleId];
/******/ 				var callbacks = [];
/******/ 				for(i = 0; i < moduleOutdatedDependencies.length; i++) {
/******/ 					dependency = moduleOutdatedDependencies[i];
/******/ 					cb = module.hot._acceptedDependencies[dependency];
                                    // ^ this is where it crashes, module is undefined
> moduleId
"./lib/client/index.js"

> installedModules[moduleId]
undefined

> installedModules[0].children
(3) ["./node_modules/babel-polyfill/lib/index.js", "./node_modules/react-hot-loader/patch.js", "./lib/client/index.js"]0: "./node_modules/babel-polyfill/lib/index.js"1: "./node_modules/react-hot-loader/patch.js"2: "./lib/client/index.js"length: 3__proto__: Array(0)

> Object.keys(installedModules).slice(0,5)
(5) ["0", "./node_modules/babel-polyfill/lib/index.js", "dll-reference dlls", "./node_modules/react-hot-loader/patch.js", "./node_modules/react-hot-loader/lib/patch.js"]0: "0"1: "./node_modules/babel-polyfill/lib/index.js"2: "dll-reference dlls"3: "./node_modules/react-hot-loader/patch.js"4: "./node_modules/react-hot-loader/lib/patch.js"length: 5__proto__: Array(0)

as you can see, the moduleId is part of the children of installedModule.0. How should hot replacement work in this situation?

@sokra
Copy link
Copy Markdown
Member

sokra commented Aug 11, 2017

Could you try if #5500 also fixes your issue?

@sokra sokra closed this in #5500 Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants