【问题标题】:editor.component.scss:17:100: ERROR: Unterminated string token - Angular + Scsseditor.component.scss:17:100:错误:未终止的字符串标记 - Angular + Scss
【发布时间】:2022-06-18 17:44:10
【问题描述】:

我在使用 scss 作为 stringUrl 的 Angular 应用程序中遇到未终止的字符串令牌错误。

@import "~bootstrap/scss/bootstrap";

.view-container, .module-row, .view, .view-inner-container {
    flex: 1;
}

.advanced-editor-wrapper {
    @extend .h-100;
    .advanced-editor-header {
        @extend .p-2, .d-flex, .align-items-center, .justify-content-between;
        border-bottom: 1px solid #333;
        h4 {
            @extend .d-inline, .m-0;
        }
        .header-button {
            @extend .mr-2, .btn;
        }
    }
    .parent-flex-container {
        @extend  .p-2, .w-100, .h-100, .d-flex, .flex-column;
        .add-view {
            @extend .btn, .h-100, .m-1, .w-100, .d-flex, .flex-column, .align-items-center, .justify-content-center; 
            flex-basis: 50px;
            background-color: transparent !important;
            border: 2px dashed #2799A5;
            color: var(--body-color);
            transition: all 0.2s ease-in;
            border-radius: 5px;
            &:hover {
                background-color: #333 !important;
                border-color: var(--body-color);
            }
            &.flex-row {
                flex-direction: row !important;
            }
        }
        .module-row-container {
            @extend  .d-flex, .flex-column, .h-100;
            .module-row {
                @extend  .d-flex, .flex-row, .mb-2;
                .view-container {
                    @extend .w-100, .d-flex, .flex-row;
                    .view-inner-container {
                        @extend  .d-flex, .flex-row;
                        .view {
                            @extend .m-1, .h-100, .position-relative, .d-flex, .flex-column, .align-items-center, .justify-content-center;
                            border-radius: 5px;
                            .view-header {
                                @extend .d-flex, .justify-content-between, .align-items-center, .p-2, .position-absolute, .w-100;
                                left: 0; 
                                top: 0;  
                                background-color: rgba(0,0,0,0.3);
                                h5 {
                                    @extend .m-0;
                                    font-family: 'Century Gothic'; 
                                    font-weight: 400; 
                                    font-size: 1rem;
                                }
                                button {
                                    @extend .p-0;
                                }
                            }
                        }
                    }
                }
            }    
        }
    }
}    

【问题讨论】:

标签: angular sass


【解决方案1】:

browserslist@angular-devkit/build-angular 包含,尝试运行:

npx browserslist --update-db

这将使用浏览器更新caniuse-lite 数据库,这帮助我摆脱了...17:100: ERROR: Unterminated string token 错误。

the trick of setting minify: false 也对我有用,但我宁愿拥有一个最新的浏览器列表,而不是关闭缩小)

【讨论】:

    【解决方案2】:

    在构建 SSR 构建时遇到了同样的问题,原来这是我的 angular.json 中的配置错误。我有一个 stylePreprocessorOptions 属性,它在 angular.json 的“构建”部分中使用样式路径定义,但对于“服务器”构建,我没有这个属性。

    我通过将完全相同的stylePreProcessorOptions 值添加到该构建配置的选项来修复它,这里是我的angular.json 的sn-p 下面:

    {
      "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
      "version": 1,
      "newProjectRoot": "projects",
      "projects": {
        "my-project": {
          "root": "",
          "sourceRoot": "src",
          "projectType": "application",
          "architect": {
            "build": {
              "builder": "@angular-devkit/build-angular:browser",
              "options": {
                "outputPath": "dist/browser",
                ...
                "stylePreprocessorOptions": {
                  "includePaths": [
                    "src/app/core/styles",
                    "src/assets"
                  ]
                ...
              }
            },
            "server": {
              "builder": "@angular-devkit/build-angular:server",
              "options": {
                "outputPath": "dist/",
                ...
                "stylePreprocessorOptions": {
                  "includePaths": [
                    "src/app/core/styles",
                    "src/assets"
                  ]
                }
              }
              ...
    

    我希望这对您有所帮助,如果有效,请告诉我。

    【讨论】:

    【解决方案3】:

    检查你导入的路径可能是错误的,或者一个';'可能会丢失

    【讨论】:

      【解决方案4】:

      在我的情况下,这是这个 scss 规则,它在以前的 Angular 版本中运行良好,但在升级到 Angular 13 后失败并出现此错误。

      .lessonName {
          width: calc(100%-200px);
          display: inline-block;
      }
      

      看到问题了吗?我也不。问题是 css 不喜欢减号 (-) 符号周围没有空格。将其更改为以下解决了该问题。认真的角度开发人员,行号会很有帮助!

      .lessonName {
          width: calc(100% - 200px);
          display: inline-block;
      }
      

      【讨论】:

        猜你喜欢
        • 2022-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-23
        • 2014-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多