我正在尝试使用Webpack和Babel将React组件捆绑到一个自包含的js文件中(以便可以将其提供给非反应性站点),但是我遇到了以下错误:“插件/预设文件是不允许导出对象,只能导出功能。'
package.json
{
"name": "onform-api",
"version": "1.0.0",
"description": "",
"main": "wrapper.js",
"scripts": {
"start": "node app.js",
"bundle-js-dev": "NODE_ENV=development BABEL_ENV=development webpack --mode development --config ./webpack.dev.config.js",
"bundle-js-prod": "NODE_ENV=production BABEL_ENV=production webpack -p --mode production --config ./webpack.prod.config.js",
"bundle-js": "npm run bundle-js-dev && npm run bundle-js-prod"
},
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"react": "^16.5.2",
"react-dom": "^16.5.2",
"webpack": "^4.22.0",
"webpack-cli": "^3.1.2"
}
}
webpack.dev.config
module.exports = {
entry: './wrapper.js',
output: {
libraryTarget: 'var',
library: 'showForm',
path: __dirname + '/builds',
filename: 'onform.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: { babelrcRoots: ['.', '../'] }
}
}
]
},
plugins: []
};
.babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
我看过类似的问题,人们似乎通过确保各种Babel依赖版本匹配来解决此问题-就我所知,我的做到了。有人知道还有什么可能导致此错误吗?