question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested SASS always shows parent line

See original GitHub issue

I must confess that this is my first time setting up gulp with gulp-sourcemaps, and I have everything working quite properly it seems, however I am experiencing an issue. My browser dev tools inspector always shows the rule location in the .scss file as being located at the topmost ‘branch’.

For example, my .scss file is as follows:

body {
  background: #33b5e5;
  color: #f0f;

  h1 {
    color: #900;
    background: #bbb;
  }

  p {
    color: #393;
  }
}

…and the web inspector will show that the p { color: #393 } rule is on “Line 1”, where it is actually on “Line 10”. I was troubleshooting this and moved the p rule outside of the body nest, and then the web inspector showed the proper “Line 10” location for that rule.

My gulp task is as follows (I am using gulp-sass):

...
    .pipe(sourcemaps.init())
        .pipe(sass().on('error', sass.logError))
    .pipe(sourcemaps.write('.', {includeContent: false, debug: true}))
...

I just can’t get these nested rules to work properly. For posterity’s sake, here’s my source map file when said p rule was nested under body:

{"version":3,"sources":["global.scss"],"names":[],"mappings":"AAAA,IAAI,CAAC;EACH,UAAU,EAAE,OAAQ;EACpB,KAAK,EAAE,IAAK,GAMb;EARD,IAAI,CAIF,EAAE,CAAC;IACD,KAAK,EAAE,IAAK;IACZ,UAAU,EAAE,IAAK,GAClB;;AAGH,CAAC,CAAC;EACA,KAAK,EAAE,IAAK,GACb","file":"global.css"}

I apologize for having to ask this question, but I am so close, as everything is working very nicely with exception to locating exact rules in my .scss file.

Thanks in advance for any help!!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:9
  • Comments:61

github_iconTop GitHub Comments

8reactions
cyphix333commented, Dec 6, 2016

@nmccready Can I ask why this is closed when the issue still exists?

4reactions
SenHengDesamiscommented, Oct 16, 2017

I’ve been having this issue and the only way I’ve managed to fix it is to run both autoprefixer and cssNano together. I’d prefer to not minify when local dev because there’s a legacy stylesheet with 20k lines in it… but this was the only thing that worked.

Maps work perfectly fine in Chrome, a little bit funky in FF (sometimes goes to closing bracket) and breaks in Safari (Goes to parent).

const gulp = require('gulp');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const gulpIf = require('gulp-if');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const nano = require('cssnano');

const processors = [
  autoprefixer({browsers: ['last 2 version']}),
  nano(),
];

gulp.task('sass', () =>
  gulp.src(config.main)
    .pipe(gulpIf(env === 'dev', sourcemaps.init()))
    .pipe(sass(config.settings))
    .on('error', handleErrors)
    .pipe(postcss(processors))
    .pipe(gulpIf(env === 'dev', sourcemaps.write()))
    .pipe(gulp.dest(config.dest))
);

versions

"autoprefixer": "^7.1.5",
"cssnano": "^4.0.0-rc.2",
"gulp": "3.9.1",
"gulp-postcss": "^7.0.0",
"gulp-sass": "^3.1.0",
"gulp-sourcemaps": "^2.6.1",
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested Sass always shows line number for parent selector in ...
When using autoprefixer, sourcemaps stop working correctly for nested selectors. They always show the line number of the parent selector.
Read more >
Parent Selector - Sass
When a parent selector is used in an inner selector, it's replaced with the corresponding outer selector. This happens instead of the normal...
Read more >
SASS/SCSS: Nesting with class as parent and tag as child
Show activity on this post. Try @at-root .class { display: block; @at-root { table#{&} { display: table; } tr#{&} { display: table-row; } ......
Read more >
Sass nesting - Free tutorial to learn HTML and CSS
The space between .parent and .child defines a hierarchy: this selector targets HTML elements with class="child" nested within class=" ...
Read more >
Sass/SCSS Nesting Tutorial - KoderHQ
In this Sass/SCSS tutorial we learn how to nest CSS selectors inside other selectors. We also cover nesting with combinators and the parent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found