webpack-dev-server npm start报错

发布于 2022-09-05 20:42:16 字数 3892 浏览 15 评论 0

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']  
    }  
};  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

摇划花蜜的午后 2022-09-12 20:42:18

怎么做已经告诉你了:

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

webpack2不支持 未知的配置项

如若梦似彩虹 2022-09-12 20:42:18

提示中已经说了

resolve: {  
        root:'',    //根据提示去掉这个
        extensions: ['', '.js', '.json', '.less']  
    }  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文