【问题标题】:You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser您尝试使用标准 CSS 解析器解析 SCSS;使用 postcss-scss 解析器重试
【发布时间】:2021-09-30 13:26:25
【问题描述】:

我最近从 Angular 11 更新到 Angular 12,但在解析 CSS 时遇到了问题。 我遵循了以下每个选项:

You tried to parse SCSS with the standard CSS parser; try again with the postcss-scss parser after Angular 12 update

我已将此添加到我的 angular.json 文件中的优化中。

"optimization": {
   "scripts": true,
   "styles": {
      "minify": false,
      "inlineCritical": false
   },
   "fonts": true
},

我添加了

"inlineStyleLanguage": "scss"

作为我的默认样式语言。

我的每个 scss 文件仍然出现以下错误:

我已将我的 angular.json 文件包含在内,以防我遗漏任何信息:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "portal": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "allowedCommonJsDependencies": [
              "lodash",
              "@firebase/database",
              "angular2-chartjs",
              "@ant-design/colors",
              "@ant-design/icons-angular",
              "@ant-design/icons-angular/icons"
            ],
            "aot": true,
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/ng-zorro-antd/style/entry.less",
              "src/app/components/kit/vendors/antd/themes/default.less",
              "src/app/components/kit/vendors/antd/themes/dark.less",
              "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              "./node_modules/chartist/dist/chartist.css",
              "./node_modules/quill/dist/quill.core.css",
              "./node_modules/quill/dist/quill.bubble.css",
              "./node_modules/quill/dist/quill.snow.css",
              "./node_modules/c3/c3.min.css",
              "src/global.scss",
              "src/app/layouts/Auth/auth.component.scss"
            ],
            "scripts": [
              "./node_modules/c3/c3.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": {
                "scripts": true,
                "styles": {
                  "minify": false,
                  "inlineCritical": false
                },
                "fonts": true
              },
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": false,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "10mb"
                }
              ]
            },
            "hmr": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.hmr.ts"
                }
              ],
              "optimization": {
                "scripts": true,
                "styles": {
                  "minify": false,
                  "inlineCritical": false
                },
                "fonts": true
              },
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": false,
            },
            "demo": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.demo.ts"
                }
              ],
              "optimization": {
                "scripts": true,
                "styles": {
                  "minify": false,
                  "inlineCritical": false
                },
                "fonts": true
              },
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": false
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "aot": true,
            "browserTarget": "portal:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "portal:build:production"
            },
            "hmr": {
              "browserTarget": "portal:build:hmr",
              "hmr": true
            },
            "demo": {
              "browserTarget": "portal:build:demo"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "portal:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "inlineStyleLanguage": "scss",
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "portal-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "prefix": "",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "portal:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "portal:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "portal",
  "cli": {
    "analytics": "c2ed9326-a5b8-4009-9392-6be3b6fcfd3c"
  }
}

【问题讨论】:

  • @Brandon 不幸的是。我确实在我的问题中链接了该页面,因为我遵循了该页面上的所有建议并且知道其他人可能也已经检查过。
  • 您是否尝试在资产目录中的 scss 文件中添加忽略模式?
  • 我没有,但是这个错误不是在位于 assets 目录中的 scss 文件中生成的,所以我认为这不会有帮助吗?该文件位于我的应用程序目录中。
  • 嗯。我还没有看到组件的 .scss 文件中出现此错误,仅针对资产目录中引用的文件。组件的 .scss 文件是否从资产中导入任何内容?

标签: css angular sass angular12


【解决方案1】:

如果所有其他配置看起来都正确。值得检查报告文件中的语法是否有任何奇怪之处。

在迁移到 NG11 并从存储库中删除 Node-Sass 时,我在一些文件上收到了此错误。其他帖子提到这是由于资产文件夹中的 sass 文件导致的,但不是我的情况。

就我而言,有/deep/ 的用法。 Dart-Sass 似乎对此感到窒息。用 ::ng-deep 替换该语法解决了我的问题。

【讨论】:

    猜你喜欢
    • 2021-08-08
    • 2011-04-25
    • 2013-12-17
    • 2021-04-25
    • 2017-10-14
    • 2012-11-07
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    相关资源
    最近更新 更多