Babel.js 如何避免“无效的配置对象,Webpack已使用与API架构不匹配的配置对象进行初始化”,

d4so4syb  于 7个月前  发布在  Babel
关注(0)|答案(4)|浏览(62)

我正在使用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"
  }
}


有谁能告诉我我哪里错了吗?提前感谢

3lxsmp7m

3lxsmp7m1#

你能试试这个脚本吗?

"scripts": {
  "start": "webpack-dev-server --mode development --open --hot",
  "build": "webpack --mode production"
}

字符串
另外,确保webpack配置名为webpack.config.js

jucafojl

jucafojl2#

问题出在脚本中使用的选项格式上

"scripts": {
    "start": "webpack-dev-server — mode development — open — hot",
    "build": "webpack — mode production"
  },

字符串
在运行webpack build时传递的选项应该像--mode一样使用,但是你已经使用了上面的-

r6hnlfcb

r6hnlfcb3#

entry假设有相对路径而不是绝对路径。

entry: {  main: "./src/index.js" },

字符串

bn31dyow

bn31dyow4#

检查package.json文件中的“main”属性

{
"main": "node_modules/expo/AppEntry.js",
}

字符串

相关问题