[BUG] - scss styles not found in v6
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
-
create an angular project that uses
scss -
add stylePreprocessorOptions to
.angular-cli.json"stylePreprocessorOptions": { "includePaths": ["styles/"] }, -
make a styles directory in src/
-
add a
_settings.scssfile in src/styles directory -
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)
This seems to be a problem only after updating to 6.0.0-beta.6
Confirmed, same here. Won't work for ng build as well.
Dupe of #10007
Workaround: add ./src to the path
"stylePreprocessorOptions": {
"includePaths": ["./src/scss"]
}
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"]
}
Where in the angular.json do you guys add the stylePreprocessorOptions?
@ciesielskico stylePreprocessirOptions go at the same level as styles, not in styles. Hope that helps.
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?
@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"
}
}
}
@ciesielskico I noticed you have node_modules in your stylePreprocessorOptions change "../node_modules/bootstrap/scss" to "node_modules/bootstrap/scss"
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.
I find a workaround
In vendor.scss adding at the end of the file :
@import './global';
I have encountered this issue on @v6.0.6. I'm trying to import global scss variables into component's scss styles
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
But what about JavaScript, from Node.js, which SOLUTION for this BUG? Can anyone help? Unfortunate in!
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.
npm install node-sass
solve for me
I don't understand why isn't writed here instructions
@FabioParigi Thank You!!!!! :D :D :D
@itboygr It's a pleasure, you are welcome
npm install node-sass perfecto funciona bien gracias FabioParigi