【发布时间】:2021-08-08 22:36:54
【问题描述】:
从 Angular 11 更新到 12 后,ng serve 现在抛出错误:
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/_colors.scss:1:4: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/custom-bootstrap.scss:1:1: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/global.scss:296:12: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
Error: /Users/btaylor/work/angular-apps/mdsl-authoring/assets/scss/mdsl-composer/mdsl-composer-variables.scss:103:1: Unknown word
You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser
所讨论的 SCSS 文件都没有做任何特别的事情。 _colors.scss 例如就是:
// Bootstrap Overrides
$text-secondary: #2E93B1;
$text-muted: #ccc;
$link-color: #2E93B1;
.text-secondary {
color: $text-secondary !important;
}
// LabCorp UI Overrides
$theme-colors: (
'primary': #003A70,
'secondary': #2E93B1,
'success': #155724,
'danger': #790E1D,
'warning': #C59C38,
'info': #007A6E,
'light': #EDF1F4,
'dark': #0B1519,
);
// UI design colors
$primary: #007FA3;
$highlighted: #D57800;
$accent: #5F456F;
$accent-secondary: #808080;
$related: #D1EAF1;
所以我不确定解析器在抱怨什么 Unknown word。
我没有在网上找到很多关于 Angular 错误的信息。
项目代码的其余部分将按预期编译,但现在应用程序将无法运行。我不确定在这里提供什么其他代码,但我很乐意发布任何有助于调试的代码。
该错误特定于 Angular CLI。我们的项目使用 Angular Universal,构建代码并通过 Node 提供服务按预期工作。
【问题讨论】:
-
升级 ang 11 > ang 12 后我也有同样的经历
-
@user576700 在 angular.json 中的
development配置中将buildOptimizer和optimization设置为 false。这就是为我解决的问题。 -
有效,将 buildOptimizer 和优化更新为 false;虽然编译器说这些已被弃用并且应该在浏览器构建器选项中设置 - 谢谢!
-
开启优化不是解决办法...
-
@jmeinlschmidt 请记住,仅当在本地运行
ng serve时禁用 buildOptimizer,而不是在生产环境中。
标签: angular angular-cli