vue项目报错Cannot find module '@vue/cli-plugin-babel/preset'解决笔记!

PS D:\WorkSpace\wwwroot\thinkphp\vue-test> npm run serve

> serve
> vue-cli-service serve

 INFO  Starting development server...
98% after emitting CopyPlugin

 ERROR  Failed to compile with 1 error                                                                       上午2:36:22

 error  in ./src/main.js

Syntax Error: Error: Cannot find module '@vue/cli-plugin-babel/preset'
Require stack:
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\@babel\core\lib\config\files\plugins.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\@babel\core\lib\config\files\index.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\@babel\core\lib\index.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\babel-loader\lib\index.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\loader-runner\lib\loadLoader.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\loader-runner\lib\LoaderRunner.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\webpack\lib\NormalModule.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\webpack\lib\NormalModuleFactory.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\webpack\lib\Compiler.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\webpack\lib\webpack.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\@vue\cli-service\lib\commands\serve.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\@vue\cli-service\lib\Service.js
- D:\WorkSpace\wwwroot\thinkphp\vue-test\node_modules\@vue\cli-service\bin\vue-cli-service.js
    at loadPreset.next (<anonymous>)
    at createDescriptor.next (<anonymous>)
    at Array.forEach (<anonymous>)
    at Generator.next (<anonymous>)


 @ multi (webpack)-dev-server/client?http://192.168.31.122:8080/sockjs-node (webpack)/hot/dev-server.js ./src/main.js

windows有使用到的命令:
PS D:\WorkSpace\wwwroot\thinkphp\vue-test> history

  Id CommandLine
  -- -----------
 128 del .\package-lock.json
 129 del .\node_modules\   #选A全部
 130 cls #清屏
 131 dir #查看文件列表
 132 npm cache clear --force #强制删除缓存
 133 npm install
 
 174 npm install @vue/cli-plugin-babel/preset --save-dev  #此种方法不能解决,抱其它错误
 175 npm install @babel/core @babel/preset-env #此方法可以解决
 176 npm run serve

解决方法:

更新babel配置babel.config.js文件。使用@babel/preset-env而不是babel-preset-env

然后执行:npm install @babel/core @babel/preset-env

#源文件:
module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ]
}


#修改后的文件:
module.exports = {
  presets: [
    "@babel/preset-env"
  ]
}


推荐阅读更多精彩内容