我正在练习使用 React 构建一个按钮,单击该按钮时计数器会加 1。我现在需要使用 Webpack 打包所有内容,以便可以在浏览器中运行它。我运行以下命令:
webpack --watch --mode=development
并得到以下错误:
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.module.rules[0].use has an unknown property 'query'. These properties are valid:
object { ident?, loader?, options? }
这是我的webpack.config.js
const path = require('path');
module.exports = {
entry: './entry.jsx',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.jsx?$/,
use: {
loader: 'babel-loader',
query: {
presets: ['@babel/env', '@babel/react']
}
},
}
]
},
devtool: 'source-map',
resolve: {
extensions: [".js", ".jsx", "*"]
}
};
this is package.json
{
"name": "click-counter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"postinstall": "webpack",
"webpack": "webpack --watch --mode=development"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.1.2"
}
}
我需要做什么来修复此错误?