Couldn't find preset "@babel/preset-env" relative to directory

 一.webpack 打包是出现如下错误

Couldn't find preset

二.修改后配置

①.检查安装

"babel-loader": "^7.1.5",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-stage-2": "^6.24.1",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",

②.babelrc配置

tips(该文件创建在webpack.config.js同级目录,没有该文件时创建文件名输入为)

.babelrc.

具体文件内容

{
  "plugins": [
     [
      "transform-runtime",
      {
        "polyfill": false
      }
     ]
   ],
   "presets": [
     [
       "env",
       {
         "modules": false
       }
     ],
     "stage-2"
  ]
}

③.webpack.config.js配置

  module: {
    rules: [
      {
        test: '/\.js$/',
        exclude: '/(node_modules)/', // 排除文件
        loader: 'babel-loader'
      }
    ]
  }

参考:https://www.cnblogs.com/tugenhua0707/p/9452471.html author:龙恩0707

 

你可能感兴趣的:(前端)