我正在尝试将主题应用于角度应用程序。\n我认为我创建的 src/theme.scss 文件本身可以正常工作;但当我导入“~@angular/material/theming”时,出现错误:
\nModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):\nSassError: Can't find stylesheet to import.\n \xe2\x95\xb7\n5 \xe2\x94\x82 @forward '../cdk/a11y/index.import';\n \xe2\x94\x82 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n \xe2\x95\xb5\n node_modules\\@angular\\material\\_theming.scss 5:1 @use\n src\\theme.scss 2:1 root stylesheet\n \nRun Code Online (Sandbox Code Playgroud)\n我调查了几个帖子,但无法解决我的问题。
\n这是我的 src/theme.scss :
\n@use "~@angular/material/theming" as mat;\n\n\n@include mat-core();\n\n$app-primary: mat.define-palette(mat.$indigo-palette, 500);\n$app-accent: mat.define-palette(mat.$orange-platte, 600);\n\nRun Code Online (Sandbox Code Playgroud)\n这是/material/_theming.scss:
\n// Forwards all public API mixins so they can be imported from a single entry point.\n// Note that we have to forward the `.import` files for backwards-compatibility with\n// projects that don't use Sass modules and include the `mat-`-prefixed mixins.\n\n@forward '../cdk/a11y/index.import';\n@forward '../cdk/overlay/index.import';\n@forward '../cdk/text-field/index.import';\n\n@forward './core/core-legacy-index';\n@forward './autocomplete/autocomplete-legacy-index';\n@forward './badge/badge-legacy-index';\n@forward './bottom-sheet/bottom-sheet-legacy-index';\n@forward './button-toggle/button-toggle-legacy-index';\n@forward './button/button-legacy-index';\n@forward './card/card-legacy-index';\n@forward './checkbox/checkbox-legacy-index';\n@forward './chips/chips-legacy-index';\n@forward './datepicker/datepicker-legacy-index';\n@forward './dialog/dialog-legacy-index';\n@forward './divider/divider-legacy-index';\n@forward './expansion/expansion-legacy-index';\n@forward './form-field/form-field-legacy-index';\n@forward './grid-list/grid-list-legacy-index';\n@forward './icon/icon-legacy-index';\n@forward './input/input-legacy-index';\n@forward './list/list-legacy-index';\n@forward './menu/menu-legacy-index';\n@forward './paginator/paginator-legacy-index';\n@forward './progress-bar/progress-bar-legacy-index';\n@forward './progress-spinner/progress-spinner-legacy-index';\n@forward './radio/radio-legacy-index';\n@forward './select/select-legacy-index';\n@forward './sidenav/sidenav-legacy-index';\n@forward './slide-toggle/slide-toggle-legacy-index';\n@forward './slider/slider-legacy-index';\n@forward './snack-bar/snack-bar-legacy-index';\n@forward './sort/sort-legacy-index';\n@forward './stepper/stepper-legacy-index';\n@forward './table/table-legacy-index';\n@forward './tabs/tabs-legacy-index';\n@forward './toolbar/toolbar-legacy-index';\n@forward './tooltip/tooltip-legacy-index';\n@forward './tree/tree-legacy-index';\nRun Code Online (Sandbox Code Playgroud)\n和我的 angular.json:
\n "$schema": "./node_modules/@angular/cli/lib/config/schema.json",\n "version": 1,\n "newProjectRoot": "projects",\n "projects": {\n "TodoNg": {\n "projectType": "application",\n "schematics": {\n "@schematics/angular:application": {\n "strict": true\n }\n },\n "root": "",\n "sourceRoot": "src",\n "prefix": "app",\n "architect": {\n "build": {\n "builder": "@angular-devkit/build-angular:browser",\n "options": {\n "outputPath": "dist/TodoNg",\n "index": "src/index.html",\n "main": "src/main.ts",\n "polyfills": "src/polyfills.ts",\n "tsConfig": "tsconfig.app.json",\n "assets": [\n "src/favicon.ico",\n "src/assets"\n ],\n "styles": [\n "src/styles.css",\n "src/theme.scss"\n ],\n "scripts": []\n },\n "configurations": {\n "production": {\n "budgets": [\n {\n "type": "initial",\n "maximumWarning": "500kb",\n "maximumError": "1mb"\n },\n {\n "type": "anyComponentStyle",\n "maximumWarning": "2kb",\n "maximumError": "4kb"\n }\n ],\n "fileReplacements": [\n {\n "replace": "src/environments/environment.ts",\n "with": "src/environments/environment.prod.ts"\n }\n ],\n "outputHashing": "all"\n },\n "development": {\n "buildOptimizer": false,\n "optimization": false,\n "vendorChunk": true,\n "extractLicenses": false,\n "sourceMap": true,\n "namedChunks": true\n }\n },\n "defaultConfiguration": "production"\n },\n "serve": {\n "builder": "@angular-devkit/build-angular:dev-server",\n "configurations": {\n "production": {\n "browserTarget": "TodoNg:build:production"\n },\n "development": {\n "browserTarget": "TodoNg:build:development"\n }\n },\n "defaultConfiguration": "development"\n },\n "extract-i18n": {\n "builder": "@angular-devkit/build-angular:extract-i18n",\n "options": {\n "browserTarget": "TodoNg:build"\n }\n },\n "test": {\n "builder": "@angular-devkit/build-angular:karma",\n "options": {\n "main": "src/test.ts",\n "polyfills": "src/polyfills.ts",\n "tsConfig": "tsconfig.spec.json",\n "karmaConfig": "karma.conf.js",\n "assets": [\n "src/favicon.ico",\n "src/assets"\n ],\n "styles": [\n "src/styles.css",\n "src/theme.scss"\n ],\n "scripts": []\n }\n }\n }\n }\n },\n "defaultProject": "TodoNg"\n}\nRun Code Online (Sandbox Code Playgroud)\n我使用的 Angular 版本是 12.1.2。有什么建议如何解决这个问题吗?
\n我刚刚遇到了同样的问题。这是我的 package.json 中的版本不匹配。
我运行了更新,所有 @Angular 包的版本均为“^12.1.4”,除了 @Angular/cdk 为“^11.xx”,更改它以"@angular/cdk": "^12.1.4"解决问题。
| 归档时间: |
|
| 查看次数: |
2393 次 |
| 最近记录: |