角度浏览器-esbuild错误:无法解析绝对路径[插件角度CSS资源]

问题描述 投票:0回答:1

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 typescript sass esbuild nx-workspace
1个回答
4
投票

解决我的问题的方法是将以下内容添加到 angular.json:

"options": {
  "stylePreprocessorOptions": {
    "includePaths": [""]
  },
}

© www.soinside.com 2019 - 2024. All rights reserved.