Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
SassError: no se puede encontrar la hoja de estilo para importar. @use '~@angular/material' como tapete;

Creé un proyecto Angular usando la CLI. Estoy usando SCSS e incluí material angular con un tema personalizado iirc. Agregué un par de componentes ficticios y la aplicación siguió funcionando bien. Luego necesitaba diseñar mis componentes usando material angular. Para hacerlo, agregué @use '~@angular/material' as mat; a la primera línea de mi archivo style.scss . Una vez que hice esto, la aplicación ya no se compilará. Siempre arroja el siguiente error:

 ERROR in ./src/styles.scss (./node_modules/css-loader/dist/cjs.js??ref--13-1!./node_modules/postcss-loader/src??embedded!./node_modules/resolve-url-loader??ref--13-3!./node_modules/sass-loader/dist/cjs.js??ref--13-4!./src/styles.scss) Module build failed (from ./node_modules/sass-loader/dist/cjs.js): SassError: Can't find stylesheet to import. ╷ 1 │ @use '~@angular/material' as mat; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ╵ src/styles.scss 1:1 root stylesheet

No tengo idea de lo que estoy haciendo mal; Tenía la impresión de que importar material angular de esta manera simplemente funcionaría. ¿Estoy haciendo algo mal?

Aquí está mi archivo completo style.scss si eso es útil:

 @use '~@angular/material' as mat; // Custom Theming for Angular Material // For more information: https://material.angular.io/guide/theming @import '~@angular/material/theming'; // Plus imports for other components in your app. // Include the common styles for Angular Material. We include this here so that you only // have to load a single css file for Angular Material in your app. // Be sure that you only ever include this mixin once! @include mat-core(); // For each palette, you can optionally specify a default, lighter, and darker hue. $aphrodite-primary: mat-palette($mat-indigo); $aphrodite-accent: mat-palette($mat-pink, A200, A100, A400); // The warn palette is optional (defaults to red). $aphrodite-warn: mat-palette($mat-red); // Create the theme object. A theme consists of configurations for individual // theming systems such as "color" or "typography". $aphrodite-theme: mat-light-theme(( color: ( primary: $aphrodite-primary, accent: $aphrodite-accent, warn: $aphrodite-warn, ) )); // Include theme styles for core and each component used in your app. // Alternatively, you can import and @include the theme mixins for each component // that you are using. @include angular-material-theme($aphrodite-theme); /* You can add global styles to this file, and also import other style files */ @import '~normalize.css'; @import 'sassVars.scss'; html, body { height: 100%; } html{ background: $nullGray; min-width: 400px; } body { font-family: Roboto, "Helvetica Neue", sans-serif; background: $canvas; max-width: $bodyWidth; margin: auto; height: 100%; @include elevation(16); }

Aquí está mi archivo angular.json :

 { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "myapp": { "projectType": "application", "schematics": { "@schematics/angular:component": { "style": "scss" } }, "root": "", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "baseHref" : "/app/", "deployUrl": "/app/", "outputPath": "dist/myapp", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "aot": true, "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [] }, "configurations": { "production": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "optimization": true, "outputHashing": "all", "sourceMap": false, "extractCss": true, "namedChunks": false, "extractLicenses": true, "vendorChunk": false, "buildOptimizer": true, "budgets": [ { "type": "initial", "maximumWarning": "2mb", "maximumError": "5mb" }, { "type": "anyComponentStyle", "maximumWarning": "6kb", "maximumError": "10kb" } ] } } }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "browserTarget": "myapp:build" }, "configurations": { "production": { "browserTarget": "myapp:build:production" } } }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "myapp:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.scss" ], "scripts": [] } }, "lint": { "builder": "@angular-devkit/build-angular:tslint", "options": { "tsConfig": [ "tsconfig.app.json", "tsconfig.spec.json", "e2e/tsconfig.json" ], "exclude": [ "**/node_modules/**" ] } }, "e2e": { "builder": "@angular-devkit/build-angular:protractor", "options": { "protractorConfig": "e2e/protractor.conf.js", "devServerTarget": "myapp:serve" }, "configurations": { "production": { "devServerTarget": "myapp:serve:production" } } } } } }, "defaultProject": "myapp", "cli": { "analytics": "0ded4b78-d900-44ea-8ad2-b5cbba677e06" } }
over 4 years ago · Santiago Trujillo
5 answers
Answer question

0

Si alguien vuelve a recibir este error, lo siguiente me ayudó:

Tuve el mismo problema, eliminé mi tema angular personalizado y olvidé eliminar los estilos de ruta del archivo angular.json , luego cambié @use '~@angular/material' as mat; para @use '@angular/material' as mat; .

Después de eliminar la ruta de estilos para el cliente, actualicé el material angular. Luego, simplemente reinicie su uso de VSCode porque a veces no se actualiza por sí solo.

over 4 years ago · Santiago Trujillo Report

0

intenta de esta manera:

 @use '@angular/material' as mat;

sin el símbolo ~.

Espero que funcione para ti

over 4 years ago · Santiago Trujillo Report

0

Para Angular 13, intente eliminar el símbolo de tilde ( ~ ) de la ruta, así que importe como:

 @use '@angular/material' as mat;

Funciona a las mil maravillas.

over 4 years ago · Santiago Trujillo Report

0

Como es habitual con las API de Google, existe una confusión entre la versión 11 y la versión 12 de Angular Material.

[Respuesta corta]

En SCSS, parecen haber desaprobado el uso de @import favoreciendo la sintaxis @use . Parece que Angular Material implementó este cambio en algún lugar alrededor de v11->12
(También soy un novato. Esta es mi mejor suposición).

Mire este video de YouTube para tener una idea general de la diferencia.

Hay una razón por la cual Google Angular es el marco más temido de 2020 en Stack Overflow :) Entonces depende de la versión de Angular Material que esté usando

[Respuesta larga]
En Angular Material v11, parecen usar la sintaxis @import , y en v12 parecen favorecer la sintaxis @use .

Por lo tanto, parece que está tratando de usar un tutorial o tema diseñado con Angular Material v11 en mente que usa la sintaxis @import y lo mezcla con la sintaxis @use de Angular Material v12. La mayor diferencia entre los dos es que la sintaxis @use hace que el SCSS tenga un prefijo, por lo que los nombres de las funciones cambian ligeramente, por ejemplo

 //angular material v11 which uses @import syntax @import '~@angular/material/theming';//notice that the file imported is also different @include mat-core(); $candy-app-primary: mat-palette($mat-indigo); //notice that functions not Namespaced $candy-app-accent: mat-palette($mat-pink, A200, A100, A400);

Mientras que el mismo ejemplo usa material angular v12 que usa la sintaxis @use

 @use '~@angular/material' as mat; $candy-app-primary: mat.define-palette(mat.$indigo-palette, 500); //notice that functions are prefixed with Namespace mat. This is a feature of the scss @use directive $candy-app-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);

[Todavía tengo que encontrar una manera de encontrar los nombres de función correctos en las 2 versiones. No es trivial migrar un tema manualmente, especialmente cuando eres un novato]

Como puede ver, es fácil que falte una hoja de estilo dependiendo de si está utilizando Material v11 o 12. Buena suerte. selección de versión

over 4 years ago · Santiago Trujillo Report

0

Aparentemente, había estado leyendo la documentación incorrecta para mi versión. El código anterior tiene dos cosas que deben cambiarse para que funcione para mí.

  1. No haces @use '~@angular/material' as mat; . La línea importante es @import '~@angular/material/theming'; , que ya fue puesto en el archivo por la CLI.

  2. No es @include elevation(16); , es @include mat-elevation(16); .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!