【问题标题】:Webpack Options Validation ErrorWebpack 选项验证错误
【发布时间】:2018-06-13 08:01:49
【问题描述】:

我试图在我的 Windows 10 机器中运行我的 webpack。

我在我的根文件夹中设置了 webpack。

这是我的 webpack.config.js:

const path = require("path");

const SRC_DIR = path.join(__dirname, "/client/src");
const DIST_DIR = path.join(__dirname, "client/dist");

module.exports = {
  config: `${SRC_DIR}/index.jsx`,
  output: {
    filename: `bundle.js`,
    path: DIST_DIR
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        include: SRC_DIR,
        loader: "babel-loader",
        query: {
          presets: ["react", "es2015"]
        }
      }
    ]
  },
  mode: "development"
};

然后在我的 package.json 文件中:

{
  "name": "rform",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "build": "webpack --config webpack.config.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-es2015": "^6.24.1",
    "webpack": "^4.12.0",
    "webpack-command": "^0.2.1"
  }
}

在运行 npm run build 时出现 ff 错误:

ValidationError: config-loader

  Options Validation Error

  options['config']  is an invalid additional property

    at validate (/mnt/c/xampp/htdocs/rform/node_modules/@webpack-contrib/schema-utils/dist/validate-options.js:87:15)
    at validator (/mnt/c/xampp/htdocs/rform/node_modules/@webpack-contrib/schema-utils/dist/validate-options.js:118:10)
    at resolve.then (/mnt/c/xampp/htdocs/rform/node_modules/@webpack-contrib/config-loader/lib/index.js:18:7)
    at process._tickCallback (internal/process/next_tick.js:109:7)
    at Module.runMain (module.js:607:11)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

npm ERR! Linux 4.4.0-17134-Microsoft
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build"
npm ERR! node v7.10.1
npm ERR! npm  v4.2.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! rform@1.0.0 build: `webpack --config webpack.config.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the rform@1.0.0 build script 'webpack --config webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the rform package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack --config webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs rform
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls rform
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/darrenchui/.npm/_logs/2018-06-13T07_55_50_484Z-debug.log

我确保我在 dist 和 src 文件夹中运行正确的文件设置。我在配置上做错了什么?请帮忙!

【问题讨论】:

    标签: reactjs webpack


    【解决方案1】:

    在他们的webpack-configuration 选项中没有任何称为config 的东西

    请通过以下链接查看他们的配置选项

    https://webpack.js.org/configuration/

    我想如果您在下面的选项中将config 替换为entry,它会起作用

    module.exports = {
      entry: `${SRC_DIR}/index.jsx`,
      output: {
        filename: `bundle.js`,
        path: `DIST_DIR`
      },
      module: {
        rules: [
          {
            test: /\.jsx?$/,
            include: SRC_DIR,
            exclude: /node_modules/,
            loader: "babel-loader",
            query: {
              presets: ["react", "es2015"]
            }
          }
        ]
      },
      mode: "development"
    };
    

    【讨论】:

    • 听从您的建议后出现此错误:jsfiddle.net/axnb2k8v/1
    • @JonDobie Error 说它在 node_modules 中找到了未知选项。我已经更新了我的答案并在模块选项中添加了一个排除选项。你能再试试上面的方法吗?
    猜你喜欢
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 2015-10-26
    • 2015-01-04
    • 1970-01-01
    • 2011-09-13
    相关资源
    最近更新 更多