webpack-dev-server无法运行,并出现validateSchema

时间:2018-06-02 08:26:20

标签: reactjs webpack webpack-dev-server

这是一个反应hello-world proj,在本地机器win7上,使用npm下载 包裹,运行时" webpack-dev-server --open"它有这样的错误:



F:\now\react\setup\node_modules\webpack-cli\bin\convert-argv.js:7
const validateSchema = process.webpackModule.validateSchema;

TypeError: Cannot read property 'validateSchema' of undefined
...




screenshot about error info

这是package.json和webpack.config.js



{
  "name": "setup",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server --open"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {},
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "react": "^16.4.0",
    "react-dom": "^16.4.0",
    "webpack": "^4.10.2",
    "webpack-cli": "^3.0.0",
    "webpack-dev-server": "^3.1.4"
  }
}




webpack.config.js:



const webpack = require('webpack');

module.exports = {
  
  devServer: {
    contentBase: "./src",
    historyApiFallback: true,
    inline: true
  },
   
  module: {
        rules: [
            {
                test: /(\.jsx|\.js)$/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: [
                            "env", "react"
                        ]
                    }
                },
                exclude: /node_modules/
            }
        ]
    }
}




1 个答案:

答案 0 :(得分:0)

webpack-cli大约10小时前从v2碰到了v3,看起来这可能是v3的一个bug。我还没有找到实际修复方法,但暂时的解决方法是通过手动将package.json中的版本号更改为^2.0.0来降级到webpack-cli v2。

希望能帮助你暂时解开。