打包报错Plugin/Preset files are not allowed to export objects, only functions
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/xxx/node_modules/babel-preset-es2015/lib/index.js
我的.babelrc文件是
{
"presets": ["es2015"],
"plugins": [
[ "transform-runtime", {
"helpers": false,
"polyfill": false
}
]
]
}
webpack.config.js配置是
'use strict'
const path = require('path')
const webpack = require('webpack')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const resolve = dir => path.join(__dirname, '.', dir)
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
entry: {
index: './src/index.js'
},
output: {
path: isProd?resolve('dist'): resolve(''), // 输出目录
filename: isProd?'[name].min.js':'[name].js', // 输出文件
libraryTarget: 'umd', // 采用通用模块定义
library: 'lagou-bridge-sdk', // 库名称
libraryExport: 'default', // 兼容 ES6(ES2015) 的模块系统、CommonJS 和 AMD 模块规范
globalObject: 'this' // 兼容node和浏览器运行,避免window is not undefined情况
},
devtool: '#source-map',
devServer: {
hot: true,
// ...
},
module: {
rules: [
{
test: /\.(js)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src'), resolve('test')],
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.js?$/,
exclude: /(node_modules|dist)/,
loader: 'babel-loader',
}
]
},
plugins: isProd
? [
new UglifyJsPlugin({
parallel: true,
uglifyOptions: {
warnings: false,
mangle: true
},
sourceMap: true
}),
]
: [
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin()
]
}
我的.babelrc文件修改去掉es2015
{
"presets": ["@babel/preset-env"],
"plugins": [
[ "transform-runtime", {
"helpers": false,
"polyfill": false
}
]
]
}
报错
ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
TypeError: /Users/xxx/src/index.js: this.setDynamic is not a function
把babelrc文件修改去掉plugins,修改为编译成功
"presets": ["@babel/preset-env"],