Source map not working for SCSS files
Recently I updated cli version 1.3.2 to 1.6.3 and after that I can't see scss source mapped file in developer tools in Chrome of Firefox .
Versions : 1.6.3
Angular CLI: 1.6.3
Node: 8.9.3
OS: win32 x64
Angular: 5.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic
... platform-server, router
@angular/cli: 1.6.3
@angular/language-service: 4.4.6
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.3
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0
Repro steps
- Create new angular app using
ng new sample-app - Add scss file in angular-cli.json
"styles": ["styles/styles.scss"] - Launch app using
ng serve -sm -ec - Inspect styles using chrome dev-tools.
Observed behavior
No actual scss file, only style.bundle.css where all the styles compiled.

Desired behavior
Actual scss file can be seen in the developer tools with the line number

works for me using version 6.0!!
solution:
- modify angular.json to add --extract-css, in 6.0 this argument is removed from
ng serve
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
---
},
"configurations": {
"production": {
---
},
"serve": {
"extractCss": true,
---
}
}
},
hen change serve->options->browserTarget->project-name:build to project-name:build:serve
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"open": true,
"browserTarget": "<project-name>:build:serve"
},
"configurations": {
"production": {
---
}
}
}
- run
ng serve --source-map
@metasong Thanks! That works for me. At least for "global" sass files. Component sass styles still don't get source mapped, but I don't use those anyways. Something to consider for others though.
For others' reference, source maps for sass files were broken in the CLI way back in version 1.5.0. It's getting old now, but using cli version 1.4.x and older will work as expected when running:
ng serve -sm -ec
https://github.com/angular/angular-cli/issues/8314
@CharltonC Thanks, your solution worked for me for angular cli 1.7.4. It is now showing the scss sourcemaps. #issuecomment-373430066
@frensuren , can you share the exact steps you did? having a hard time following which of the solution will work for 1.7.4
@rukshandangalla Could this ticket be closed now that v6 issue has been fixed?
@rukshandangalla For me, component sass styles still don't get source mapped (v6).
@icenold
Installed css-loader and exports-loader dependencies for @angular/cli
i) navigate to "node_modules/@angular/cli"
ii) do: npm install --save css-loader exports-loader
iii) Modify the file "node_modules@angular\cli\models\webpack-configs\styles.js" contents, mine was in line 180
Replace
const commonLoaders = [
{ loader: 'raw-loader' },
];
with this
const commonLoaders = [
{
loader: 'css-loader',
options: {
sourceMap: cssSourceMap,
import: false,
}
}
];
Also Replace
// load component css as raw strings
const rules = baseRules.map(({ test, use }) => ({
exclude: globalStylePaths, test, use: [
...commonLoaders,
{
loader: 'postcss-loader',
options: {
ident: 'embedded',
plugins: postcssPluginCreator,
sourceMap: cssSourceMap
}
},
...use
]
}));
With
// load component css as raw strings
const rules = baseRules.map(({ test, use }) => ({
exclude: globalStylePaths, test, use: [
'exports-loader?module.exports.toString()',
...commonLoaders,
{
loader: 'postcss-loader',
options: {
ident: 'embedded',
plugins: postcssPluginCreator,
sourceMap: cssSourceMap
}
},
...use
]
}));
This worked for me
Sourcemapping for General (Non-component level) SCSS Compilation
@metasong's solution works for ANGULAR 6
- modify angular.json to add
--extract-css, in 6.0 this argument is removed fromng serve
"build": { "builder": "@angular-devkit/build-angular:browser", "options": { --- }, "configurations": { "production": { --- }, "serve": { "extractCss": true, --- } } },
- Then change serve->options->browserTarget->project-name:build to
project-name:build:serve
"serve": { "builder": "@angular-devkit/build-angular:dev-server", "options": { "open": true, "browserTarget": "<project-name>:build:serve" }, "configurations": { "production": { --- } } }
- run
ng serve --source-map
Sourcemapping for Component-level SCSS Files
Can you confirm, @metasong, @frensuren, @CharltonC, @rukshandangalla, @michael-letcher?
Suprisingly, the following solution works without any configuring of Angular 6's angular.json file.
Simply add /*# sourceURL=your-comp-style.component.scss */ to the bottom of your component-level .scss file.
Code
Run
ng serve --source-map
Result in Chrome

@cedriccjmusic
Source mapping for Component-level
Can confirm that adding /*# sourceURL=navbar.component.less */ worked for me.
Note this is using LESS
Source mapping for General (Non-component level)
I don't need to do this, LESS seems to work by just using --source-map
This is causing an error for me:
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(extractsCss).
The sourceURL= solution helps at least tell you the file, but still is far from ideal. It references generated css, so line numbers do not match up and any imported styles will show as belonging to the importing file.
@daddyschmack you have a typo, it should be extractCss and not extractsCss, although I was trying this method with a new angular project and its not working with the last couple cli versions.
I found the source of the issue within the @angular-devkit/build-angular package.
You can temporarily fix this yourself editing changing the sourcemap option for both instances of postcss-loader in the following file ./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/styles.js change
sourceMap: cssSourceMap
to
sourceMap: cssSourceMap ? 'inline' : false
const rules = baseRules.map(({ test, use }) => ({
exclude: globalStylePaths, test, use: [
{ loader: 'raw-loader' },
{
loader: 'postcss-loader',
options: {
ident: 'embedded',
plugins: postcssPluginCreator,
sourceMap: cssSourceMap ? 'inline' : false
}
I'll file an issue with the @angular-devkit/build-angular repository. edit: ah that package is in this repo, ha. I submitted a pull request with the fix.
@cedriccjmusic thanks for the example!
Sadly isn't working for me with Angular cli 6.1
I get the following result:

Versions
Angular CLI: 6.1.2
Node: 8.11.1
OS: darwin x64
Angular: 6.1.1
... animations, common, compiler, core, forms, http
... platform-browser, platform-browser-dynamic, platform-server
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.7.2
@angular-devkit/build-angular 0.7.2
@angular-devkit/build-optimizer 0.7.2
@angular-devkit/build-webpack 0.7.2
@angular-devkit/core 0.7.2
@angular-devkit/schematics 0.7.2
@angular/cli 6.1.2
@angular/compiler-cli 6.1.2
@angular/language-service 6.1.2
@ngtools/webpack 6.1.2
@schematics/angular 0.7.2
@schematics/update 0.7.2
rxjs 6.2.2
typescript 2.9.2
webpack 4.9.2
Config
{
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
....
"stylePreprocessorOptions": {
"includePaths": [
"styles/core-scss"
]
},
"assets": [
....
],
"styles": [
"apps/essent/src/core.scss"
],
"scripts": []
},
"configurations": {
"production": {
....
},
"css": {
"sourceMap": true,
"extractCss": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "essent:build",
"port": 4200
},
"configurations": {
"production": {
"browserTarget": "essent:build:production"
},
"css": {
"browserTarget": "essent:build:css"
}
}
}
}
Commands
Getting the same result with build & serve
yarn ng build essent --source-map --extract-css
yarn ng serve essent --proxy-config proxy.conf.js --configuration css --source-map
@ajspera this won't fix angular-cli 1.7.4, am I right? only new 6.x.x?
@lazysergey Right. You might want to try #issuecomment-392316835 who had a hack working for 1.7.4. I would recommend getting up to 6, though. The next minor patch should have the fix in.
@ajspera were you able to get smaps to work? Is there somewhere I could read up on how to get them to work properly? I've never actually seen them work in Angular.
@BenRacicot Hmm, they said it would be in this past patch release but I don't see the commit in branch 6.2.x. It's on master, so it's in the maintainers' hands at this point. If you are desperate, you can make the changes from the commit mentioned above in your installation's source. It's only 2 lines.
Awesome thanks for replying.