无效的配置对象。网络包

时间:2018-09-12 20:39:55

标签: webpack

npm run dev给我这个错误:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'modules'. These properties are valid:
   object { mode?, amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry?, externals?, loader?, module?, name?, node?, output?, optimization?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, serve?, stats?, target?, watch?, watchOptions? }
   For typos: please correct them.
   For loader options: webpack >= v2.0.0 no longer allows custom properties in configuration.
     Loaders should be updated to allow passing options via loader options in module.rules.
     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
     plugins: [
       new webpack.LoaderOptionsPlugin({
         // test: /\.xxx$/, // may apply this only for some modules
         options: {
           modules: …
         }
       })
     ]

webpack.config.js

const path = require("path");
const htmlWebpackPlugin = require("html-webpack-plugin");
module.exports = env => {
  const no_dist = env && env.dist === "false";

  return {
    //webpack configuration
    entry: ["@babel/polyfill", "./src/js/index.js"],
    output: {
      path: path.resolve(__dirname, "dist"),
      filename: "js/bundle.js"
    },
    mode: "development",
    devServer: {
      inline: false,
      contentBase: "./dist"
    },
    plugins: [
      new htmlWebpackPlugin({
        filename: "index.html",
        template: "./src/index.html"
      })
    ],
    modules: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
            loader: "babel-loader"
          }
        }
      ]
    }
  };
};

package.json

{
  "name": "espn_project",
  "version": "1.0.0",
  "description": " project ",
  "main": "index.js",
  "scripts": {
    "dev": "webpack --mode development --env.dist=false",
    "dev:dist": "webpack --mode development",
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open"
  },
  "author": "Chris Kelly",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.0.1",
    "@babel/preset-env": "^7.0.0",
    "babel-loader": "^8.0.2",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.18.0",
    "webpack-cli": "^3.1.0",
    "webpack-dev-server": "^3.1.8"
  },
  "dependencies": {
    "@babel/polyfill": "^7.0.0"
  }
}

.babelrc

{
    "presets": ["/env"]
}

1 个答案:

答案 0 :(得分:0)

错误消息显示:

  

配置的属性'模块'未知。这些属性是有效的:object {mode?,amd?,bail?,cache?,context?,dependency?,devServer?,devtool?,entry?,externals?,loader?, module?。 ..

这是在告诉您您拥有一个名为modules的无效属性。正确的属性名称为module(不带“ s”)。