sass-loader icon indicating copy to clipboard operation
sass-loader copied to clipboard

nested styles refer to top-level parent in sourcemap line number

Open woohling opened this issue 10 years ago • 45 comments

I encountered the same issue in https://github.com/sass/node-sass/issues/1206. But according to this post, this issue has been fixed in node-sass, but it still occurred with sass-loader.

This is my sass-loader config: 'style!css?sourceMap!sass?sourceMap=true&outputStyle=expanded&sourceMapContents=true'

Any help?

woohling avatar Aug 24 '16 10:08 woohling

Mac OSX (El Capitan?) "sass-loader": "^4.0.2", "webpack": "^2.1.0-beta.25", "webpack-dev-server": "^2.1.0-beta.0" node: 6.7.0

When running the SCSS SourceMaps only point to the Parent selector and not the correct selector.

2016-10-22_0150

But as you can see it is not pointing to the correct selector. It should be pointing to line 13 not line 5.

2016-10-22_0156

However, If I run 'node-sass' in the terminal then it works fine. So it seems to be an issue with sass-loader and webpack.

Any solutions to resolve this or is there any settings in node-modules/sass-loader that I can change to get different results.

Thanks

ggedde avatar Oct 28 '16 22:10 ggedde

Same problem here. Did anyone found a workaround for this?

folmert avatar Nov 24 '16 11:11 folmert

CSS source maps can only work if every loader in the loader chain passes them through. That's necessary because webpack, only supports JS source maps out of the box.

@woohling Do you experience the same issue when you use this loader chain: style-loader?sourceMap!css-loader?sourceMap!sass?sourceMap&outputStyle=expanded&sourceMapContents=true' ?

jhnns avatar Nov 25 '16 14:11 jhnns

Just tried, but still the same problem. 😥 @jhnns

woohling avatar Nov 25 '16 15:11 woohling

I switched from sass-loader to postcss/precss and source maps are generated correctly now, so there must be something broken in sass-loader.

folmert avatar Nov 26 '16 11:11 folmert

Did anyone solve this problem?

maximusnikulin avatar Dec 28 '16 05:12 maximusnikulin

Same issue here. @import makes sourcemap point to the parent file.

pgayvallet avatar Jan 04 '17 16:01 pgayvallet

I can confirm the problem. You can test that with https://github.com/jtangelder/sass-loader/pull/374/commits/ce198d169d4a1066d214d40ba88fb0b5029c0536 and npm run test-source-map.

Unfortunately, I don't know how to fix this since we don't actually mess with the source maps.

jhnns avatar Feb 13 '17 18:02 jhnns

@jhnns Could you explain more on "we don't actually mess with the source maps". Are you saying that sass-loader doesn't create the source maps. If so then what does and how? As mentioned running "node-sass" in the terminal the source maps are fine, but running it though sass-loader and webpack they are not.

Sorry I am not too familiar with sass-loader flow. Could someone explain the difference that running sass-loader through webpack has as compared to running node-sass through the terminal.

It almost seems like the scss file is converted to (nested, expanded, or compact) prior to the source map is being applied then the css is compressed.

Is there any way to test that sass-loader is getting the full un-compacted un-compressed scss files when creating the source mappings?

ggedde avatar Feb 13 '17 19:02 ggedde

We receive the source maps directly from node-sass. But since the source maps are also processed by the css-loader and other loaders on the way, it's hard to say what's going on. Maybe they are incompatible?

It would be good if you could investigate this. Build the smallest project possible that reproduces the error and inspect the source maps in the sass-loader and then in the css-loader. You can use the style-loader to apply the styles to the DOM. The style-loader uses a BLOB url to make the source maps available to the browser. It does not change the source maps anymore, so that should be fine.

jhnns avatar Feb 14 '17 10:02 jhnns

@woohling @maximusnikulin @wayofspark @ggedde The problem still exists? If yes please create minimal reproducible test repo

alexander-akait avatar May 03 '17 14:05 alexander-akait

No longer working on the project with this issue. But I will find time to create a small demo to see if the problem still exists.

woohling avatar May 04 '17 03:05 woohling

@woohling just ping me when your do this :+1:

alexander-akait avatar May 04 '17 09:05 alexander-akait

Sorry @jhnns @evilebottnawi, I took a pause from this project. Nope, the issue still exists for me. I also just recently installed brand new ng-cli on a new laptop. Angular4.0 with CLI 1.0.2 which is using sass-loader 6.0.3

I created a small project and just had a few lines of scss code. It still pointed to the top parent node, but running node-sass works fine. Not sure what I can do to help further.

ggedde avatar May 09 '17 09:05 ggedde

@ggedde can your create minimal reproducible test repo?

alexander-akait avatar May 09 '17 12:05 alexander-akait

@evilebottnawi Yes, I can. I will let you know when I get that up.

In the meantime I did find that if I added outputStyle: 'compressed' to the sass-loader it now works for Chrome, but not FF.

So my guess is that css-loader is expecting the sass-loader to be compressed. So if sass-loader is not then you need to specify it. I am not sure how to have css-loader know what the format is. That way you wouldn't have to specify it.

So this may be an issue with css-loader and not sass-loader.

I will look at it again later tonight.

ggedde avatar May 09 '17 17:05 ggedde

@ggedde seems bugs not in sass-loader or css-loader (it makes no difference what we work on sass/scss/less and etc.). I think FF have bug, just ping me when test repo was created.

alexander-akait avatar May 09 '17 17:05 alexander-akait

Yes, FF has a bug, but Chrome doesn't work either unless you add outputStyle: 'compressed' to sass-loader. There may not be a bug with either, but there is definitely a configuration issue that is not well documented anywhere. Nor does anyone have a good grasp on how to configure css-loader with sass-loader to make the sourcemaps work properly. It would be great for us to figure it out then either someone from the sass-loader team or css-loader team right a blog post about it explaining the reasons why and how to properly configure webpack to output the correct sourcemaps. I will definitely do what I can to support it.

ggedde avatar May 09 '17 17:05 ggedde

I may be reading things incorrectly here, but I think y'all might be barking up the wrong tree if you're looking for the origin of the problem to be in sass-loader (assuming sass-loader is a webpack-specific thing).

See, I have this exact issue, of sourcemaps not referencing the right line if the @import is within a CSS selector. However, I'm using gulp—gulp-sass, gulp-sourcemaps, etc—not webpack.

Does this help any?

sandwich avatar Jul 23 '17 10:07 sandwich

@sandwich can your provide minimum reproducible test repo?

alexander-akait avatar Jul 26 '17 12:07 alexander-akait