简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM