如何在Vuejs中修复“ Webpack开发服务器无效选项”

Art*_*ngh 21 webpack-dev-server vuejs2

我正在使用,@vue/cli v3.7.0并且通过vue create myappBabel + Router + node-sass 创建了一个项目,并且我的项目已成功安装

但是当我运行npm run serve(在项目目录中)时,出现以下错误:


 INFO  Starting development server...
 ERROR  ValidationError: webpack Dev Server Invalid Options

options.clientLogLevel should be {String} and equal to one of the allowed values

 [ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]

 (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)

ValidationError: webpack Dev Server Invalid Options

options.clientLogLevel should be {String} and equal to one of the allowed values

 [ 'info', 'warn', 'error', 'debug', 'trace', 'silent' ]

 (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)

    at validateOptions (C:\Users\Dell\Desktop\myapp\node_modules\webpack-dev-server\node_modules\schema-utils\src\validateOptions.js:32:11)
    at new Server (C:\Users\Dell\Desktop\myapp\node_modules\webpack-dev-server\lib\Server.js:71:5)
    at serve (C:\Users\Dell\Desktop\myapp\node_modules\@vue\cli-service\lib\commands\serve.js:138:20)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! myapp@0.1.0 serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the myapp@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Dell\AppData\Roaming\npm-cache\_logs\2019-05-17T19_40_14_984Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我尝试了npm cache clean -f,重新安装了VueJS,重新创建了项目,但没有任何效果:(

我希望我的npm run serve工作!

ads*_*arn 14

是的,这个问题只是在过去的几个小时里突然出现了@vue/cli。我在一个新项目中也遇到了同样的事情。要解决此问题,请尝试以下操作:

  1. vue.config.js如果您还没有该文件,请在项目的根目录中创建一个文件。

  2. 将此添加到该文件:

module.exports = {
  devServer: {
    clientLogLevel: 'info'
  }
};

Run Code Online (Sandbox Code Playgroud)

然后重新运行您的项目。昨晚发生了某事clientLogLevel,预设值变得不正确。

这是一个讨论此问题的线程:GitHub


Dan*_*Dan 5

我不知道为什么会收到该错误,但是这是配置该选项的方式:

1. vue.config.js在您的根目录中创建

2.在其中输入以下内容:

module.exports = {
  devServer: {
    clientLogLevel: 'debug'
  }
}
Run Code Online (Sandbox Code Playgroud)

3.重新运行 npm run serve

您可以在此处阅读有关配置开发服务器的更多信息。