webpack配置babel时候报错ERROR in ./src/main.js Module build failed (from ./node_modules/babel-loade

报错信息
ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Plugin/Preset files are not allowed to export objects, only functions. In /Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/babel-preset-stage-0/lib/index.js
    at createDescriptor (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:178:11)
    at /Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:109:50
    at Array.map (<anonymous>)
    at createDescriptors (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPresetDescriptors (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:101:10)
    at presets (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-descriptors.js:47:19)
    at mergeChainOpts (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-chain.js:320:26)
    at /Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-chain.js:283:7
    at buildRootChain (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/config-chain.js:120:22)
    at loadPrivatePartialConfig (/Users/thinker/Desktop/practice/React/01-webpack-base/node_modules/@babel/core/lib/config/partial.js:85:55)

在这里插入图片描述
当出现这种错误的时候,就说明最新的babel已经不是这样配置的了。

解决问题:
首先,卸载之前安装的
npm uni babel-core babel-loader babel-plugin-transform-runtime -D
npm uni babel-core babel-loader babel-plugin-transform-runtime -D

在这里插入图片描述

然后,再进行如下的安装:
npm i babel-loader @babel/core @babel/runtime @babel/preset-env @babel/plugin-proposal-class-properties @babel/plugin-transform-runtime -D

在这里插入图片描述
在这里插入图片描述

另外配置也要修改 在.babelrc文件中 要配置成
{
  "presets": [
    "@babel/preset-env"
  ],
  "plugins": [
    "@babel/plugin-transform-runtime",
    "@babel/plugin-proposal-class-properties"
  ]
}

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值