earthling earthling - 24 days ago 31
Javascript Question

Webpack Module not found: Error: Cannot resolve module

I am getting a few module not found errors from webpack, but the problem is the files are actually there. I've triple-checked and I am sure the files are there, but for some reason, webpack is failing to find them. Is there any way for me to find out more information on why webpack is failing?

ERROR in ./~/react-router/BrowserRouter.js
Module not found: Error: Cannot resolve module 'history/createBrowserHistory' in [MODULE_PROJECT_ROOT]\node_modules\react-router
@ ./~/react-router/BrowserRouter.js 11:28-67

ERROR in ./~/react-router/HashRouter.js
Module not found: Error: Cannot resolve module 'history/createHashHistory' in [MODULE_PROJECT_ROOT]\node_modules\react-router
@ ./~/react-router/HashRouter.js 11:25-61

ERROR in ./~/react-router/HashRouter.js
Module not found: Error: Cannot resolve module 'history/PathUtils' in [MODULE_PROJECT_ROOT]\node_modules\react-router
@ ./~/react-router/HashRouter.js 19:17-45

ERROR in ./~/react-router/MemoryRouter.js
Module not found: Error: Cannot resolve module 'history/createMemoryHistory' in [MODULE_PROJECT_ROOT]\node_modules\react-router
@ ./~/react-router/MemoryRouter.js 11:27-65

ERROR in ./~/react-router/LocationUtils.js
Module not found: Error: Cannot resolve module 'history/PathUtils' in [MODULE_PROJECT_ROOT]\node_modules\react-router
@ ./~/react-router/LocationUtils.js 17:17-45

ERROR in ./~/react-router/LocationUtils.js
Module not found: Error: Cannot resolve module 'history/LocationUtils' in [MODULE_PROJECT_ROOT]\node_modules\react-router
@ ./~/react-router/LocationUtils.js 8:21-53

ERROR in ./~/react/lib/CSSPropertyOperations.js
Module not found: Error: Cannot resolve module 'fbjs/lib/memoizeStringOnly' in [MODULE_PROJECT_ROOT]\node_modules\react\lib
@ ./~/react/lib/CSSPropertyOperations.js 21:24-61

Answer

I've found out why webpack was unable to find the requested modules. I had provided an array of absolute paths to resolve.modulesDirectories and resolveLoader.modulesDirectories. What I had forgotten to do was including the default value for these fields in my arrays. In my case, I just prepended "node_modules" to these arrays of file paths and that solved my problem.

Comments