Skip to content

components cant support scss #7719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mm580486 opened this issue Sep 17, 2017 · 16 comments
Closed

components cant support scss #7719

mm580486 opened this issue Sep 17, 2017 · 16 comments

Comments

@mm580486
Copy link

i use scss on project(src directory) and works fine but on components scss not working (but css works fine !)

i started project with ng new ex --styles= scss command and styles.scss works good
home.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

tsconfig.app.json


{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "baseUrl": "./",
    "module": "es2015",
    "types": [],
    "sourceMap": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

Versions.

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
@angular/cli: 1.4.2
node: 8.4.0
os: darwin x64
@angular/animations: 4.4.1
@angular/common: 4.4.1
@angular/compiler: 4.4.1
@angular/core: 4.4.1
@angular/forms: 4.4.1
@angular/http: 4.4.1
@angular/platform-browser: 4.4.1
@angular/platform-browser-dynamic: 4.4.1
@angular/router: 4.4.1
@angular/cli: 1.4.2
@angular/compiler-cli: 4.4.1
@angular/language-service: 4.4.1
typescript: 2.3.4


@avatsaev
Copy link

avatsaev commented Sep 17, 2017

Having the same issue. How did this bug slip through the unit tests?

@mm580486
Copy link
Author

mm580486 commented Sep 18, 2017

@avatsaev
i for skip this issue i imported scss on styles.scss( for sample home.component.scss )

but its not good 😫

# style.scss
.
.
.
/*
    import Pages
*/

@import "app/pages/public/home/home.component";

@avatsaev
Copy link

@mm580486 you could just change css extension to scss manually, as long as your .angulat-cli.json specifies scss extension for styles, you should be fine

@mm580486
Copy link
Author

i changed angular-cli man but not working scss only work on styles.css

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "front"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.scss"
      ],
      "stylePreprocessorOptions": {
        "includePaths": [
            "app"
        ]
    },
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}

@RicardoVaranda
Copy link
Contributor

Could one of you guys provide a repo with this issue so I can take a look at the issue, can't seem to reproduce it on my own build, thanks!

@Tuizi
Copy link

Tuizi commented Sep 18, 2017

@RicardoVaranda quite simple to reproduce, using cli 1.4.2 do:

ng new web --prefix "i" --style "scss"
cd web
ng g component home

The output will be:

  create src/app/home/home.component.css (0 bytes)
  create src/app/home/home.component.html (23 bytes)
  create src/app/home/home.component.spec.ts (614 bytes)
  create src/app/home/home.component.ts (259 bytes)
  update src/app/app.module.ts (388 bytes)

Notice the home.component.css file instead of home.component.scss

@AhsanAyaz
Copy link
Contributor

Duplicate of #7624, #7644, #7647, #7708, #7715 & #7522

@Brocco
Copy link
Contributor

Brocco commented Sep 22, 2017

Closing as a duplicate

@Brocco Brocco closed this as completed Sep 22, 2017
@CraigWarford
Copy link

CraigWarford commented Feb 13, 2018

I don't think the original post is a duplicate of the above mentioned reports. I've been experiencing this for a while now as well, and working around it. As indicated by others, I create a new Angular CLI project, change the angular cli settings to use SCSS instead of CSS, rename styles.css to styles.scss, and app.component.css to app.component.scss. I run the app, and all the SCSS is compiled to CSS and delivered to the browser. I can even generate a new "home" component for the app, and it creates it as a .scss file.

But here's the problem: Any styling I put into the home.component.scss file never reaches the browser. On the other hand, if I add a child component to the home page, suddenly, all the home.component.scss gets to the browser now. But the new child component styles do not. It's like the compiler doesn't get to the very last level of scss to send to the client.

EDIT: Interesting enough, if you import the scss into either the styles.scss or app.component.scss, it compiles and loads just fine. I believe that was mentioned previously as well.

@ghost
Copy link

ghost commented Feb 14, 2018

@CraigWarford agreed. It seems like out of the box, without any tweaking, app.component.scss content gets ignored completely. I've tried styles for HTML tags (body) and classes. My current workaround is to include a file directly through .angular-cli.json, but as Craig said:

All .scss files imported into sub-components seem to work, except the top level app one.

@chris31389
Copy link

chris31389 commented Jul 5, 2018

This works @angular/cli 6.0.8

angular.json

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
    "newProjectRoot": "projects",
    "projects": {
        "my-app": {
            "root": "",
            "sourceRoot": "src",
            "projectType": "application",
            "prefix": "app",
            "schematics": {
                "@schematics/angular:component": {
                    "styleext": "scss"
                }
            },
            ...
       }
   }
}

@ihsanberahim
Copy link

@chris31389 i only found [email protected]

How to get 6.0.8?

@ganeshkbhat
Copy link

ganeshkbhat commented Nov 14, 2018

@ihsanberahim If that's a valid v then npm install @[email protected] -g should work. I do npm install @angular-cli -g (after force cleaning cache) which loads latest stable release and is backwards compatible. Someone correct me here if I am mistaken

@ihsanberahim
Copy link

npm i -g @angular/cli@6

@manalis
Copy link

manalis commented Dec 6, 2018

I found below answer on Stack Overflow and it worked for me.

::ng-deep .className {}

https://stackoverflow.com/questions/46218037/component-scss-inside-component-folder-does-not-work/46218064

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests