在
nx
环境中从 Angular v15 迁移到 v16 期间,我的构建过程遇到了许多与我在 scss
文件中寻址资产的形式相关的错误。
例如:
✘ [ERROR] Could not resolve "~apps/platform/src/assets/img/bank-card-overlay.png" [plugin angular-css-resource]
apps/platform/src/app/shared/components/add-credit-card-modal/add-credit-card-modal.component.scss:40:24:
40 │ ...image: url("~apps/platform/src/assets/img/bank-card-overlay.png");
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can remove the tilde and use a relative path to reference it, which should remove this error.
The plugin "angular-compiler" was triggered by this import
apps/platform/src/app/shared/components/add-credit-card-modal/add-credit-card-modal.component.ts:3:33:
3 │ ...CE__1 from "angular:jit:style:file;./add-credit-card-modal.compo...
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我没有尝试使用相对路径,因为我需要按照它的方式来维护开发体验。
有什么解决办法吗?
解决我的问题的方法是将以下内容添加到 angular.json:
"options": {
"stylePreprocessorOptions": {
"includePaths": [""]
},
}