angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

[BUG] - scss styles not found in v6

Open sfabriece opened this issue 8 years ago • 23 comments

Versions

<!--
Output from: `ng --version`.
If nothing, output from: `node --version` and `npm --version`.
  Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)
-->
Angular CLI: 6.0.0-beta.6
Node: 9.5.0
OS: win32 x64
Angular: 6.0.0-rc.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 6.0.0-beta.4
@angular/cli: 6.0.0-beta.6
@angular/material: 6.0.0-beta.4
@angular-devkit/architect: 0.0.7
@angular-devkit/build-optimizer: 0.4.6
@angular-devkit/build-webpack: 0.0.7
@angular-devkit/core: 0.4.6
@angular-devkit/schematics: 0.4.6
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 6.0.0-beta.6
@schematics/angular: 0.4.6
@schematics/package-update: 0.4.6
typescript: 2.7.2
webpack: 4.1.1

Repro steps

  1. create an angular project that uses scss

  2. add stylePreprocessorOptions to .angular-cli.json

    "stylePreprocessorOptions": {
         "includePaths": ["styles/"]
       },
    
  3. make a styles directory in src/

  4. add a _settings.scss file in src/styles directory

  5. import settings in styles.scss in src/

    @import 'settings';
    

Observed behavior

ERROR in ../node_modules/@angular-devkit/build-webpack/src/angular-cli-files/plugins/raw-css-loader.js!../node_modules/postcss-loader/lib??embedded!../node_modules/sass-loader/lib/loader.js??ref--14-3!./styles.scss
Module build failed:
@import 'settings';
^
      File to import not found or unreadable: settings.

Desired behavior

ng serve to work without errors

Mention any other details that might be useful (optional)

sfabriece avatar Mar 21 '18 13:03 sfabriece

This seems to be a problem only after updating to 6.0.0-beta.6

sfabriece avatar Mar 21 '18 14:03 sfabriece

Confirmed, same here. Won't work for ng build as well.

dirkluijk avatar Mar 22 '18 09:03 dirkluijk

Dupe of #10007

admosity avatar Mar 26 '18 19:03 admosity

Workaround: add ./src to the path

"stylePreprocessorOptions": {
  "includePaths": ["./src/scss"]
}

markgoho-EDT avatar Apr 05 '18 20:04 markgoho-EDT

This worked for me: notice that I removed ./ from the path. This is probably because the root in angular.json is set to "".

"stylePreprocessorOptions": {
  "includePaths": ["src/scss"]
}

sfabriece avatar Apr 06 '18 17:04 sfabriece

Where in the angular.json do you guys add the stylePreprocessorOptions?

alexciesielski avatar Apr 10 '18 18:04 alexciesielski

@ciesielskico stylePreprocessirOptions go at the same level as styles, not in styles. Hope that helps.

sfabriece avatar Apr 10 '18 18:04 sfabriece

I have this now in my serve script:

"serve": {
	"builder": "@angular-devkit/build-angular:dev-server",
	"options": {
		"browserTarget": "waluty-klient:build",
		"stylePreprocessorOptions": {
			"includePaths": ["styles/", "../node_modules/bootstrap/scss"]
		}
	},
	"configurations": {
		"production": {
			"browserTarget": "waluty-klient:build:production"
		}
	}
},

but I'm getting the following error:

Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(stylePreprocessorOptions).
Error: Schema validation failed with the following errors:
  Data path "" should NOT have additional properties(stylePreprocessorOptions).
    at MergeMapSubscriber._registry.compile.pipe.operators_1.concatMap.validatorResult [as project] (C:\Users\xxx\node_modules\@angular-devkit\core\src\workspace\workspace.js:139:42)

Can you post your angular.json please?

alexciesielski avatar Apr 10 '18 18:04 alexciesielski

@ciesielskico there you go:

{
  "$schema":
    "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "my-app": {
      "root": "",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/my-app",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              {
                "glob": "favicon.ico",
                "input": "src",
                "output": "/"
              },
              {
                "glob": "robots.txt",
                "input": "src",
                "output": "/"
              },
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              }
            ],
            "styles": [
              {
                "input": "src/styles.scss"
              }
            ],
            "stylePreprocessorOptions": {
              "includePaths": ["src/styles"]
            },
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "src": "src/environments/environment.ts",
                  "replaceWith": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "my-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "my-app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "my-app: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",
            "styles": [
              {
                "input": "styles.scss"
              }
            ],
            "scripts": [],
            "assets": [
              {
                "glob": "favicon.ico",
                "input": "src/",
                "output": "/"
              },
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              }
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    },
    "my-app-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "my-app:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": ["**/node_modules/**"]
          }
        }
      }
    }
  },
  "schematics": {
    "@schematics/angular:component": {
      "inlineStyle": true,
      "inlineTemplate": true,
      "flat": true,
      "spec": true,
      "prefix": "pre",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "pre"
    }
  }
}


sfabriece avatar Apr 10 '18 19:04 sfabriece

@ciesielskico I noticed you have node_modules in your stylePreprocessorOptions change "../node_modules/bootstrap/scss" to "node_modules/bootstrap/scss"

AntonisFK avatar Apr 13 '18 18:04 AntonisFK

I'm having the same issue with importing sass files from node_modules, this seems to work only if you prefix your import statement with a tilde @import '~@material/button/mdc-button'; instead of @import '@material/button/mdc-button';. Though it doesn't completely solve the issue as imports within your sass imports will break too.

kornect avatar May 05 '18 16:05 kornect

I find a workaround

In vendor.scss adding at the end of the file :

@import './global';

ndywicki avatar Jul 02 '18 15:07 ndywicki

I have encountered this issue on @v6.0.6. I'm trying to import global scss variables into component's scss styles

paulmelero avatar Jul 06 '18 09:07 paulmelero

ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/styles.scss) Module build failed (from ./node_modules/sass-loader/lib/loader.js): Error: Cannot find module 'node-sass' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15) at Function.Module._load (internal/modules/cjs/loader.js:529:25) at Module.require (internal/modules/cjs/loader.js:658:17) at require (internal/modules/cjs/helpers.js:22:18) at Object.sassLoader (/home/samokaku/propertech/node_modules/sass-loader/lib/loader.js:46:72) i got this error after doing this command : ng serve -o

SamiChagar avatar Nov 23 '18 22:11 SamiChagar

But what about JavaScript, from Node.js, which SOLUTION for this BUG? Can anyone help? Unfortunate in!

raydacosta avatar Nov 25 '18 15:11 raydacosta

Please, a solution that solves it, because it's been two weeks since I've tried to squeeze from ANDROID java Native to IONIC and this Bug is occurring.

raydacosta avatar Nov 25 '18 15:11 raydacosta

npm install node-sass solve for me I don't understand why isn't writed here instructions

FabioParigi avatar Nov 30 '18 16:11 FabioParigi

@FabioParigi Thank You!!!!! :D :D :D

itboygr avatar Dec 10 '18 08:12 itboygr

@itboygr It's a pleasure, you are welcome

FabioParigi avatar Dec 10 '18 08:12 FabioParigi

npm install node-sass perfecto funciona bien gracias FabioParigi

davidbarrera75 avatar Mar 14 '19 01:03 davidbarrera75