question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 12 migration does NOT refactor @import to @use AND @use still has at-rule unknown

See original GitHub issue

Bug Report

Affected Package

@angular/dev-kit

Is this a regression?

No, @use never worked.

Description

After updating to Angular 12 and reading the blog post @use was a long awaited feature, I was really looking forward to. I was reading about it recently while diving into sass. I updated and migrated to Angular 12 and my app.theme.scss file was NOT migrated. I checked in my package.json, I could not find node-sass, and the only scss loader I was using, was in the core Angular package.

Minimal Reproduction

Update to Angular 12 using ng update, migrating from 11.

I am not sure how to reproduce this on stackblitz, I can’t use the command-line.

If StackBlitz is not suitable for reproduction of your issue, please create a minimal GitHub repository with the reproduction of the issue. A good way to make a minimal reproduction is to create a new app via ng new repro-app and add the minimum possible code to show the problem. Share the link to the repo below along with step-by-step instructions to reproduce the problem, as well as expected and actual behavior.

Issues that don’t have enough info and can’t be reproduced will be closed.

You can read more about issue submission guidelines here: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#submit-issue –>

Exception or Error




Your Environment

Angular Version:


Angular CLI: 12.0.0
Node: 14.16.1
Package Manager: npm 7.12.0
OS: darwin x64

Angular: 12.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, material, platform-browser, platform-browser-dynamic
... router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.0
@angular-devkit/build-angular   12.0.0
@angular-devkit/core            12.0.0
@angular-devkit/schematics      12.0.0
@angular/fire                   6.1.0-rc.2
@schematics/angular             12.0.0
rxjs                            6.6.7
typescript                      4.2.4


Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mlc-mlapiscommented, Jun 7, 2021

@leylita Yes. @forward and @use should be at the beginning of the file.

The following block can be probably placed independently by the internal order logic of styles.

@include mat.core();
$custom-theme-primary: mat.define-palette(mat.$blue-palette, 500, 500, 500);
$custom-theme-accent:  mat.define-palette(mat.$orange-palette, A200, A100, A400);
$custom-theme-warn:    mat.define-palette(mat.$red-palette);
$custom-theme: mat.define-light-theme($custom-theme-primary, $custom-theme-accent, $custom-theme-warn);
@include `mat.all-component-themes($custom-theme);
2reactions
leylitacommented, Jun 7, 2021

Hi!

I have the same problem with my angular project. I did the migration of Angular 11 to Angular 12 (“@angular/material”: “12.0.3”) Since that I can’t build anymore my app.

My error is that :

./src/styles.scss - Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: @use rules must be written before any other rules.
   ╷
52 │ @use '~@angular/material' as mat;

My configuration is :

Angular CLI: 12.0.3
Node: 14.15.3
Package Manager: npm 6.14.13
OS: win32 x64

Angular: 12.0.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.3
@angular-devkit/build-angular   12.0.3
@angular-devkit/core            12.0.3
@angular-devkit/schematics      12.0.3
@angular/flex-layout            12.0.0-beta.34
@schematics/angular             12.0.3
rxjs                            6.6.7
typescript                      4.2.4

I installed the sass npm package npm install -g sass

My styles.scss is like this :

@use '~@angular/material' as mat;
@include mat.core();
$custom-theme-primary: mat.define-palette(mat.$blue-palette, 500, 500, 500);
$custom-theme-accent:  mat.define-palette(mat.$orange-palette, A200, A100, A400);
$custom-theme-warn:    mat.define-palette(mat.$red-palette);
$custom-theme: mat.define-light-theme($custom-theme-primary, $custom-theme-accent, $custom-theme-warn);
@include mat.all-component-themes($custom-theme);

And my angular.json is like this :

"projects": {
    "myAngularProject": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/myAngularProject",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              "src/environments"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": [],
            "vendorChunk": true,
            "extractLicenses": false,
            "buildOptimizer": false,
            "sourceMap": true,
            "optimization": false,
            "namedChunks": true
          },

I followed this guideline angular material

Please can you tell me what am i missing?

Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating Angular Material to v12 does not remove old import ...
So now, I have both @use and import in my styles.scss file. Should I remove @import '~@angular/material/theming; ? As I understand, it will...
Read more >
Best coding practices from an Angular 12 migration - ITNEXT
The API endpoint's controller must know WHAT it has to do, but it doesn't have to know how to do it. The controller...
Read more >
Migrating to MDC-based Components - Angular Material
The components from the following imports have been refactored: ... This will be apparent if your dialog does not use any of the...
Read more >
AngularJS: Developer Guide: Migrating from Previous Versions
It has been deprecated and removed from the documentation since 2014. Applications that still use it should migrate to Protractor. Technically, it should...
Read more >
Migrate from Eclipse to IntelliJ IDEA - JetBrains
You can import either an Eclipse workspace or a single Eclipse project ... when launching IntelliJ IDEA is that it has no workspace...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found