webpack-dev-server npm start报错

webpack-dev-server 在运行npm start后报错,错误如下:

clipboard.png

WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.resolve has an unknown property 'root'. These properties are valid:
   object { alias?, aliasFields?, cachePredicate?, cacheWithContext?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
 - configuration.resolve.extensions[0] should not be empty.
    at webpack (E:\clone with github\React\node_modules\webpack\lib\webpack.js:19:9)
    at Object.<anonymous> (E:\clone with github\React\server.js:5:22)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)

npm ERR! Windows_NT 10.0.15063
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.2
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! reacttest@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reacttest@1.0.0 start script 'node server.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 reacttest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs reacttest
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls reacttest
npm ERR! There is likely additional logging output above.

下面是我的webpack.config.js:

var webpack = require('webpack');  
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');  
var path = require('path');  
  
module.exports = {  
    devtool: 'eval',  
    entry: [  
        'webpack-dev-server/client?http://localhost:3000',  
        'webpack/hot/only-dev-server',  
         './src/js/entry.js'  
    ],  
    output: {  
        path: path.join(__dirname, 'dist'),  
        filename: 'bundle.js',  
        publicPath: '/static/'  
    },  
    plugins: [  
        new webpack.HotModuleReplacementPlugin(),  
        commonsPlugin  
    ],  
  
    module: {  
        loaders: [  
            {  
                test: /\.css$/,  
                loader: 'style-loader!css-loader'  
            },  
            {  
                test: /\.jsx?$/,  
                loaders: ['react-hot', 'babel'],  
                exclude: /node_modules/,  
  
            },  
            {  
                test: /\.(png|jpg)$/,  
                loader: 'url-loader?limit=8192'  
            },  
            {  
                test: /\.less$/,  
                loader: 'style-loader!css-loader!less-loader'  
            },  
            {  
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,  
                loader: "url-loader?limit=10000&mimetype=application/font-woff"  
            },  
            {  
                test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,  
                loader: "file-loader"  
            }  
        ]  
    },  
    resolve: {  
        root:'',  
        extensions: ['', '.js', '.json', '.less']  
    }  
};  
阅读 8.8k
2 个回答

怎么做已经告诉你了:

 Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.resolve has an unknown property 'root'

webpack2不支持 未知的配置项

提示中已经说了

resolve: {  
        root:'',    //根据提示去掉这个
        extensions: ['', '.js', '.json', '.less']  
    }  
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题