简体   繁体   English

angular v11 + Scss 编译失败

[英]angular v11 + Scss failed to compile

We have an existing angular project with scss setup architecture like this but after upgrading to angular v11 with angular cli v11, we are facing this issue, not able to find what is causing it我们有一个现有的 angular 项目,具有类似这样scss设置架构,但是在升级到 angular v11 和 angular cli v11 后,我们发现它无法找到导致此问题的原因, 这个

can someone help us?有人可以帮助我们吗?

I have also created stackblitz as well.我也创建了stackblitz

Thank you in advance.先感谢您。

Error: ./src/app/app.component.scss
Module Error (from ./node_modules/postcss-loader/dist/cjs.js):
(Emitted value instead of an instance of Error) CssSyntaxError: C:\Users\VNelapati\Projects\NXT_Gen\app.component.scss:11:4: Can't resolve './assets/iconscaret-down-blue-16.png' in 'C:\Users\VNelapati\Projects\NXT_Gen\ax-upgrade\angular11\src\app'

   9 |     right: 16px;
  10 |     cursor: pointer;
> 11 |     background-image: url($icon-url +"caret-down-blue-16.png");
     |    ^
  12 | }
  13 | 

I have cloned your repo instead of your stackblitz since there are instances that Stackblitz doesn't recognize absolute paths on scss imports我已经克隆了你的 repo而不是你的 stackblitz,因为有些实例 Stackblitz 无法识别scss imports的绝对路径

Have found the problem and In order to resolve your issue:已找到问题并为了解决您的问题:

1.) Put / at the start and end of your $icon-url on your _variables.scss : 1.) 将/放在$icon-urlstartend_variables.scss

$icon-url: "/assets/icons/";

2.) On your app.component.scss 2.) 在你的app.component.scss

remove @import "../style/app.scss";删除@import "../style/app.scss"; since this is quite redundant as variables is already imported on your standards scss file.因为这是非常多余的,因为variables已经导入到您的standards scss 文件中。 Just have it like this:就像这样:

@import "standards";


body {
    width: 24px;
    height: 24px;
    top: 16px;
    right: 16px;
    cursor: pointer;
    background-image: url($icon-url +"caret-down-blue-16.png");
}

You have a problem with your url.您的 url 有问题。 Based on your stakckbliz, you have an icons folder inside assets but the error tells you it is trying to access ./assets/iconscaret-down-blue-16.png .根据您的 stakckbliz,您在assets中有一个icons文件夹,但错误告诉您它正在尝试访问./assets/iconscaret-down-blue-16.png You want ./assets/icons/caret-down-blue-16.png , so add the slash to either $icon-url or append it before caret-down-blue-16.png .您想要./assets/icons/caret-down-blue-16.png ,因此在caret-down-blue-16.png之前将斜杠添加到$icon-url或 append 。 The first option is better if you have several icons, so you do the global fix如果您有多个图标,第一个选项会更好,因此您可以进行全局修复

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular V11:NullInjectorError:没有 ControlContainer 的提供程序 - Angular V11: NullInjectorError: No provider for ControlContainer 如何解决这个错误? angular v11 原理图工作流程失败。 看上面 - How to solve this error ? angular v11 The Schematic workflow failed. See above Angular v8 到 v11 - 禁用常春藤的 entryComponents 问题 - Angular v8 to v11 - entryComponents issue with Ivy disabled 在架构中找不到“tsconfig”-将 tslint 迁移到 eslint (Angular v11) - 'tsConfig' is not found in schema - Migrating tslint to eslint (Angular v11) 如何测试动态加载组件的 Angular (v11) 组件 - How test an Angular (v11) component that loads components dynamically Angular 自定义材质主题在 v11 到 14 升级后未加载 - Angular Custom Material Theme not loading after v11 to 14 upgrade Angular 2+ (v11) 自动将 URL 中的片段 hash (#) 编码为 %23 - Angular 2+ (v11) automatically encode fragment hash (#) in URL into %23 在 Angular v11/12 中使用 d3.stack() 实现堆积条形图时出现问题 - Problem implementing Stacked Bar Chart using d3.stack() in Angular v11/12 断言错误:这个 TNode 不属于这个 TView。 angular 从 v7.1 更新到 v11 之后 - ASSERTION ERROR: This TNode does not belong to this TView. after angular update from v7.1 to v11 Primeng v11 进度微调器不变色 - Primeng v11 progress spinner does not change color
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM