我正在使用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 '—' twice.
-> A non-empty array of non-empty strings
型
这是我的webpack.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"
}
}
型
有谁能告诉我我哪里错了吗?提前感谢
4条答案
按热度按时间3lxsmp7m1#
你能试试这个脚本吗?
字符串
另外,确保webpack配置名为
webpack.config.js
?jucafojl2#
问题出在脚本中使用的选项格式上
字符串
在运行webpack build时传递的选项应该像
--mode
一样使用,但是你已经使用了上面的-
。r6hnlfcb3#
entry
假设有相对路径而不是绝对路径。字符串
bn31dyow4#
检查package.json文件中的“main”属性
字符串