Skip to content
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

[BUG] - scss styles not found in v6 #10036

Closed
sfabriece opened this issue Mar 21, 2018 · 23 comments
Closed

[BUG] - scss styles not found in v6 #10036

sfabriece opened this issue Mar 21, 2018 · 23 comments

Comments

@sfabriece
Copy link

sfabriece commented Mar 21, 2018

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
Copy link
Author

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

@dirkluijk
Copy link

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

@admosity
Copy link
Contributor

Dupe of #10007

@markgoho-EDT
Copy link

Workaround: add ./src to the path

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

@sfabriece
Copy link
Author

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"]
}

@alexciesielski
Copy link

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

@sfabriece
Copy link
Author

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

@alexciesielski
Copy link

alexciesielski commented Apr 10, 2018

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?

@sfabriece
Copy link
Author

@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"
    }
  }
}

@AntonisFK
Copy link

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

@kornect
Copy link

kornect commented May 5, 2018

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.

@ndywicki
Copy link

ndywicki commented Jul 2, 2018

I find a workaround

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

@import './global';

@gangsthub
Copy link

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

@SamoKaku
Copy link

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

@raydacosta
Copy link

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

@raydacosta
Copy link

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.

@FabioParigi
Copy link

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

@itboygr
Copy link

itboygr commented Dec 10, 2018

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

@FabioParigi
Copy link

@itboygr
It's a pleasure, you are welcome

@davidbarrera75
Copy link

npm install node-sass
perfecto funciona bien gracias FabioParigi

@xavierluz
Copy link

@sfabriece
Copy link
Author

for those upgrading to version 8 and finding that sass is broken:

yarn add node-sass fibers -D

as explained in the release notes for version 8

@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