Javascript 如何避免;无效的配置对象。已使用与API架构不匹配的配置对象初始化Web包。”;
我正在使用webpack设置react项目。但在运行下面的命令之后Javascript 如何避免;无效的配置对象。已使用与API架构不匹配的配置对象初始化Web包。”;,javascript,reactjs,webpack,babeljs,Javascript,Reactjs,Webpack,Babeljs,我正在使用webpack设置react项目。但在运行下面的命令之后 npm start 我在终端中有以下错误 × 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.entry['main'] should not contain the item '—
npm start
我在终端中有以下错误
× 「wds」: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.entry['main'] should not contain the item '—' twice.
-> A non-empty array of non-empty strings
这是我的webpack.config.js文件
const path = require('path');
const HWP = require('html-webpack-plugin');
module.exports = {
entry: path.join(__dirname, '/src/index.js'),
output: {
filename: 'build.js',
path: path.join(__dirname, '/dist')},
module:{
rules:[{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
plugins:[
new HWP(
{template: path.join(__dirname,'/src/index.html')}
)
]
}
下面是package.json的代码
{
"name": "aragon-connect-1.1",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "webpack-dev-server — mode development — open — hot",
"build": "webpack — mode production"
},
"author": "Author Name",
"license": "ISC",
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^8.1.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^4.3.0",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
}
}
有人能告诉我哪里出了错吗?
提前感谢您能试用这个脚本吗
"scripts": {
"start": "webpack-dev-server --mode development --open --hot",
"build": "webpack --mode production"
}
另外,请确保webpack config被称为
webpack.config.js
?问题在于脚本中使用的选项格式
"scripts": {
"start": "webpack-dev-server — mode development — open — hot",
"build": "webpack — mode production"
},
运行webpack build时传递的选项应该像
--mode
那样使用,但您已经使用了上面的-
。条目
假定具有相对路径而不是绝对路径
entry: { main: "./src/index.js" },
不确定这是否是格式问题,但我发现这很奇怪:
-模式开发
。它应该是--模式开发
,两个连字符后面不跟空格。与start
和build
中的其他参数相同。感谢您的回复,但对我的情况没有帮助