先贴上错误
Module build failed: Error: Cannot find module '@babel/core'
babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'.
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object.<anonymous> (F:\project\react-todos\node_modules\babel-loader\lib\index.js:10:11)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at loadLoader (F:\project\react-todos\node_modules\loader-runner\lib\loadLoader.js:18:17)
at iteratePitchingLoaders (F:\project\react-todos\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
at runLoaders (F:\project\react-todos\node_modules\loader-runner\lib\LoaderRunner.js:365:2)
at NormalModule.doBuild (F:\project\react-todos\node_modules\webpack\lib\NormalModule.js:182:3)
@ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.jsx
解决方法
其实在错误中已经有了提示
babel-loader@8 requires Babel 7.x (the package ‘@babel/core’). If you’d like to use Babel 6.x (‘babel-core’), you should install ‘babel-loader@7’.
官方默认babel-loader | babel 对应的版本需要一致: 即babel-loader需要搭配最新版本babel
解决
回退低版本
npm install -D babel-loader@7 babel-core babel-preset-env
更新到最高版本:
npm install -D babel-loader @babel/core @babel/preset-env webpack]