开发者问题收集

错误输出为:未知选项:'--extract-css'

2019-08-31
1942

我收到错误“NPM 脚本‘start’退出时未指示 Angular CLI 正在监听请求。错误输出为:未知选项:‘--extract-css’”

我有一个项目,我已经有一段时间没做了。它基于 Visual Studio angular 模板。启动项目时,我收到错误:

An unhandled exception occurred while processing the request. AggregateException: One or more errors occurred. (One or more errors occurred. (The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: Unknown option: '--extract-css'

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! [email protected] start: ng serve --extract-css "--port" "54197" npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start 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:

)) System.Threading.Tasks.Task.GetResultCore(bool waitCompletionNotification)

InvalidOperationException: The NPM script 'start' exited without indicating that the Angular CLI was listening for requests. The error output was: Unknown option: '--extract-css'

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! [email protected] start: ng serve --extract-css "--port" "54197" npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start 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:

Microsoft.AspNetCore.SpaServices.AngularCli.AngularCliMiddleware+d__3.MoveNext()

我希望能够从 Visual Studio 运行 angular 模板项目。通过 angular cli 运行时,它运行良好。

2个回答

我发现通过将 package.json 从:

"scripts": { "ng": "ng", "start": "ng serve --extract-css", "build": "ng build --extract-css",

更改为:

"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build",

可以在 Visual Studio 中成功运行 angular 项目模板。基本上只需删除“--extract-css”

Juan C. Gonzalez
2019-08-31

若要在脚本中添加参数,请在 -- 后添加它们。

在上述情况下,而不是:

"scripts": { "ng": "ng", "start": "ng serve --extract-css", "build": "ng build --extract-css",

您可以将其写为:

"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build -- --extract-css",

附注: --extract-css 不适用于 serve,请参阅 angular 问题 #10532

2bit
2019-11-25