首页 > 解决方案 > 将 webpack 与 React 一起使用时,如何修复运行时错误?

问题描述

如果我的 webpack 无法在终端中编译文件,我该如何开始调试这个问题?

这是终端中的错误:

ERROR in ./app/components/App.js
Module not found: Error: Can't resolve 'react-router-dom' in '/Users/andrewtalle/Desktop/github-battle/app/components'
 @ ./app/components/App.js 21:18-45
 @ ./app/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/index.js

ERROR in ./app/components/Home.js
Module not found: Error: Can't resolve 'react-router-dom' in '/Users/andrewtalle/Desktop/github-battle/app/components'
 @ ./app/components/Home.js 21:11-38
 @ ./app/components/App.js
 @ ./app/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/index.js

ERROR in ./app/components/Nav.js
Module not found: Error: Can't resolve 'react-router-dom' in '/Users/andrewtalle/Desktop/github-battle/app/components'
 @ ./app/components/Nav.js 3:14-41
 @ ./app/components/App.js
 @ ./app/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./app/index.js
Child html-webpack-plugin for "index.html":
     1 asset
    Entrypoint undefined = index.html
    [./node_modules/html-webpack-plugin/lib/loader.js!./app/index.html] 324 bytes {0} [built]
    [./node_modules/lodash/lodash.js] 527 KiB {0} [built]
    [./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 492 bytes {0} [built]
    [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 546 bytes {0} [built]
ℹ 「wdm」: Failed to compile.

标签: javascriptnode.jsreactjswebpacknpm-start

解决方案


推荐阅读