I'm trying to use react-grid-layout in a .NET core MVC application. I've set up node.js and react using this guide, which works just fine. Now I'm trying to include a react-grid-layout component, but I get errors while running webpack. First it demanded to have the babel preset es2015
installed, even though I'm already using @babel/preset-env
. After installing es2015
the error changed to:
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions.
Searching for other people having this issue I only found posts, where the solution was to use the babel presets @babel/preset-react
and @babel/preset-env
, which I already do. Here is what I found so far:
My webpack.config.js
:
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractCSS = new ExtractTextPlugin('allstyles.css')
module.exports = {
entry: {'main': './wwwroot/src/app.js'},
output: {
path: path.resolve(__dirname, 'wwwroot/dist'),
filename: 'bundle.js',
publicPath: 'dist/'
},
plugins: [
extractCSS,
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
}),
new webpack.optimize.UglifyJsPlugin()
],
module: {
rules: [
{
test: /\.css$/,
use: extractCSS.extract(['css-loader? minimize'])
},
{
test: /\.js?$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react' ,'@babel/preset-env']
}
}
}]
}
};
And my package.json
{
"name": "ASPNetCoreReact",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"wbp": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.24.1"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"@babel/preset-react": "^7.0.0-beta.40",
"aspnet-webpack": "^2.0.3",
"babel-loader": "^8.0.0-beta.2",
"bootstrap": "^4.0.0",
"css-loader": "^0.28.10",
"extract-text-webpack-plugin": "^3.0.2",
"isomorphic-fetch": "^2.2.1",
"jquery": "^3.3.1",
"popper.js": "^1.13.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-grid-layout": "^0.16.5",
"style-loader": "^0.20.2",
"uglifyjs-webpack-plugin": "^1.2.2",
"webpack": "^3.11.0",
"webpack-hot-middleware": "^2.21.1"
},
"description": ""
}
I've also pushed an example project to github where the error can be reproduced.
Any ideas where the error might come from? Maybe I just set up something wrong? I'm totally new to .net core, node and react, so that is quite probable. Thanks in advance.
I finally found the solution myself. As suggested in this issue at github I downgraded babel-loader 8.0.0-beta
, @babel/core
, @babel/preset-env
and @babel/preset-react
to babel-loader 7.1.4
, babel-core
, babel-preset-env
and babel-preset-react
. Additionally I had to upgrade es2015
to env
in the .babelrc
of react-grid-layout
and react-resizeable
as suggested in this pull request.