angular-cli: 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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 22
- Comments: 87 (4 by maintainers)
Links to this issue
Commits related to this issue
- fix(@angular-devkit/build-angular): load component source maps inline so they work without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs https... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs https://git... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are loaded into the DOM breaks the default sourcemap option postcss-loader option docs ht... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are loaded into the DOM breaks the default sourcemap option postcss-loader option docs ht... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs https://g... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs https://git... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs https://git... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs https://git... — committed to ajspera/angular-cli by ajspera 6 years ago
- fix(@angular-devkit/build-angular): load style source maps inline so they work (#11729) without this, the way styles are into the DOM breaks the default sourcemap option postcss-loader option docs ... — committed to angular/angular-cli by ajspera 6 years ago
works for me using version 6.0!!
solution:
ng serve
hen change serve->options->browserTarget->project-name:build to project-name:build:serve
ng serve --source-map
Some Context:
I remembered it was a weird thing in Webpack config where I had to add extra config to allow sourcemap (in addition to the plugin config).
Solution: In “node_modules@angular\cli\models\webpack-configs\common.js” file, in line 162, Add a line
devtool: 'source-map',
in the returned common configuration object in thegetCommonConfig
function, e.g.Tested with the following Commands in terminal (also works with Sass @import):
Sourcemapping for General (Non-component level) SCSS Compilation
@metasong’s solution works for ANGULAR 6
--extract-css
, in 6.0 this argument is removed fromng serve
project-name:build:serve
ng serve --source-map
v1.7.3
still no change. 👎version 1.7.4 still not work, even try patched with
devtool: 'source-map'
, Plz show me how to fix this issue.Issue still present in v1.7.0 The workaround DOES NOT WORK in v1.7.0!
Edit: Not sure why down voted, the work around does not work for me anymore when using CLI v1.7.0
patch doesn’t work in 1.7.0. Trying to work on styling is a nightmare without sourcemaps, please fix!
I have same issue, and still wait for fixing. This is a critical issue, it blocks rapid development.
Same issue here when I upgraded from 1.4.7 to 1.6.5. Please fix, this is a major blocker!
This is making it very hard to work and debug css styling issues.
I’ve had this problem from 1.5 onwards
This is main reason why I am still using Angular 4 and cli 1.4.x in production and not upgrading to Angular 5.
Dnia 5 stycznia 2018 04:42 Rukshan Lakshitha Dangalla <notifications@github.com> napisał(a): 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.3Node: 8.9.3OS: win32 x64Angular: 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-opt 0.0.36@angular-devkit/core: 0.0.22@angular-devkit/schemati 0.0.42@ngtools/json-schema: 1.1.0@ngtools/webpack: 1.9.3@schematics/angular: 0.1.11@schematics/schematics: 0.0.11typescript: 2.4.2webpack: 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. zasobygwp.pl Desired behavior Actual scss file can be seen the developer tools with the line number zasobygwp.pl — You are receiving this because you are subscribed to this thread. Reply to this email directly, zasobygwp.pl view it on GitHub , or zasobygwp.pl mute the thread .
@smlombardi You have entered the line in the wrong place.
This is where I imagine you have placed it:
in needs to be in the return object one level higher:
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
version 1.7.3 does’t work, even patched with
devtool: 'source-map'
, anyone know whyOne just wonders when the team is planning to actually fix this critical piece of tooling.
Had some spare time to test it out. As suspected, it was caused by “raw-loader” the plugin. I tried enabling the sourcemap with the option for “raw-loader” plugin like follows (approx. line 180) but unfortunately didn’t work.
Perhaps the good news is that it is not a super verbose work around.It has turned into a verbose work around. It seems that “raw-loader” is only used for Html beside the “styles.js” file. Not sure what it may break though. Please do check.Solution
devtool: 'source-map'
in the “common.js” file as per previous discussionnpm install --save css-loader exports-loader
commonLoaders
(approx. line 180) withcss-loader
one, for example:b) Right underneath the
commonLoaders
, add the'exports-loader?module.exports.toString()',
above the...commonLoaders
. This is the same as CLI 1.6.6 and eliminates the error “compiler.js:2520 Uncaught Error: Expected ‘styles’ to be an array of strings.” in the devtool consoleTest Context:
Tested with the following Commands in terminal (also works with Sass @import):
My2cents. @michael-letcher I have tested using CLI 1.7.0 and can confirm the work around is no longer working. It was strange as the Webpack API related to the sourcemap fix did not change as far as I am concerned.
Did a little more digging & comparing the webpack config file, found that the new CLI is using Webpack plugin “raw-loader” which does not yet support sourcemap (somehow the ticket has been closed but I am not sure if the sourcemap has been implemented). See the link below: https://github.com/webpack-contrib/raw-loader/pull/8
As for reference, there is a difference block of code in “webpack-config/style.js” file, the
commonLoaders
variable:“raw-loader” could be the issue here.
Source map not working for LESS files
I have the same issue with Less files too.
The component LESS files appear, but the styles brought in via the CLI are not.
Versions
@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
with this
Also Replace
With
This worked for me
This gets to a point where it just takes too much effort or work around to solve a fundamental issue. There are too many unknowns as in what we need to test against the solution so that other functionalities don’t break because the work around involves changes in so many areas. I think it would best to leave this to original author as in why there was a major change in the implementation from v1.7.0 onwards.
I can share some observations for reference purpose only. Apart from the changes I mentioned, if you do either of the following, the font error mentioned by @smlombardi disappears.
node_modules\@angular\cli\models\webpack-configs\style.js
file from CLI v1.6.6 to CLI v1.70 it will work. (requires an extra npm dependency calledcssnano
for the CLI)PostcssCliResources
in thepostcssPluginCreator
constant in thenode_modules\@angular\cli\models\webpack-configs\style.js
file, like following (It is using anode_modules\@angular\cli\plugins\postcss-cli-resources.js
file which was not in v1.6.6 before):Hope this helps. For now I myself am just going to stick with CLI v1.6.6
+1, no more source maps with
@angular/cli: 1.7.1
I create such file as postinstall can patch it. inspired from angular aio https://github.com/angular/angular/tree/master/aio/tools/cli-patches
in your project create following files
tools/cli-patches/patch.js
tools/cli-patches/webpack-enable-sourcemap.patch
package.json
Glad it works for everyone. Cheers.
As I can see many folks have this issue. What can we do about this?
It does not show references to my project’s scss files nor to bootstrap 4’s scss files. Only to styles.bundle.css.
Still
sourceMap
/extractCSS
is not working for component specific stylesI 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
to
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.
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.
@CharltonC Thanks, your solution worked for me for angular cli 1.7.4. It is now showing the scss sourcemaps. #issuecomment-373430066
downgraded to 1.6.6 and applied fix by @CharltonC - source maps work as expected. my steps:
npm cache clear --force
npm cache verify
npm i @angular/cli@1.6.6
or use exact version in package.json"@angular/cli": "1.6.6",
and donpm i
node_modules@angular\cli\models\webpack-configs\common.js:162
@smlombardi I ended up going with gulp for now because I am working on styling and needed something that would also work for deploy. My config may be oversimplified, but it works. I am using font-awesome 4.7, bootstrap 4 and a single entry point for global SCSS. I added the font-awesome fonts as assets in .angular-cli.json so they get copied, a style sheet reference to project’s index.html and emptied the styles array. In my styles/styles.scss file I set $fa-css-prefix, $fa-font-path vars appropriately, then import font-awesome and bootstrap .SCSS from relative node_modules paths.
I have gulp calling ng cli commands defined in package.json. NOTE: May run into issues without –delete-output-path=false on ng build command
added to index.html head:
relevant styles.scss:
relevant package.json scripts:
gulp dependencies:
gulpfile.js:
Hope this is of some help.
I use
ng serve -sm -ec
and it does not work for global styles. I don’t use component styles.@michael-letcher Thanks. missed that. I confirm it’s working now for scss.
@smlombardi, it looks like your devtool definition is not at right level of configuration. Examine the structure of return {…} @CharltonC provided. The exact line number in the common.js file may vary. I hope this helps.
@smlombardi Yeah, seems like a bug from at least 1.6.2 onwards
I am not even using
~
we use:The css is complied and works for all of these, but no source maps.