Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source-map error with bootstrap-sass ampersand #429

Closed
aaronrobb opened this issue Jan 3, 2017 · 16 comments
Closed

Source-map error with bootstrap-sass ampersand #429

aaronrobb opened this issue Jan 3, 2017 · 16 comments

Comments

@aaronrobb
Copy link

Version: v7.3.0
Platform :Linux me-via-3384591 4.2.0-c9 #2 SMP Thu Oct 20 09:52:05 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Subsystem:
I'm seeing the following error when running 'gulp' on a install that runs bootstrap-sass:


/home/ubuntu/workspace/wp-content/themes/mysite-sage/node_modules/source-map/lib/source-map-generator.js:277
throw new Error('Invalid mapping: ' + JSON.stringify({
^

Error: Invalid mapping: {"generated":{"line":2872,"column":48},"source":"../bower_components/bootstrap-sass/assets/stylesheets/bootstrap/mixins/_buttons.scss","original":{"line":46,"column":-13},"name":null}

It looks like source-map doesn't like bootstrap-sass's ampersands.
The actual line that the error refers to looks like:

&:focus, 
&.focus { 
color: $color; 
background-color: darken($background, 10%); 
border-color: darken($border, 25%); 
}

If I add a space after the ampersand, the error jumps down to the next line with an ampersand, etc.

Is there a way around this? Maybe a different version is needed to run bootstrap-sass??

@hupad
Copy link

hupad commented Jan 12, 2017

@aaronrobb I am facing the same issue. Did you find any fix to this?

@aaronrobb
Copy link
Author

aaronrobb commented Jan 13, 2017

@hupadhyayula I didn't find a clean solution. All i could do is in my gulp file, I found these lines and commented them out:

.pipe(function() { return gulpif(enabled.maps, sourcemaps.init()); })

This will just bypass the sourcemaps during the gulp process. Probably a bad idea, but it works for now!

@hupad
Copy link

hupad commented Jan 13, 2017

@aaronrobb yeah, that's what I have done as well. This is only happening when you use source maps with scss files, and it's because of the negative column number you have "-13" in your case. Because in source-map-generator.js file, it's doing some validation and checking if the column value is positive or not.

@aaronrobb
Copy link
Author

@hupadhyayula Yah its strange. I created a new install, set it up normally, ran a gulp and it worked. Then added in the bootstrap sass module and it broke again.

But its weird if this doesn't happen to other people. I'm just wondering if something in my code is triggering this error but the system sees it as a different error....

@hupad
Copy link

hupad commented Jan 13, 2017

@aaronrobb the other thing that you could do, which I just started to explore is to use gulp-clean-css instead of using any other minifying plugins. This way

var minifyCSS = require('gulp-clean-css');

gulp.task('build-css', ['css-to-scss'], function() {
	return gulp.src(paths.scss.source)
		.pipe(sass())
		.pipe(concat(paths.scss.build_name))
		.pipe(minifyCSS({sourceMap: true}, function(details) {
			console.log(details.sourceMap);	// use this source map to write it to your destination path.
		}))
		.pipe(gulp.dest(paths.scss.build_destination));
});

@tfmccomas
Copy link

tfmccomas commented Jan 17, 2017

@hupadhyayula and @aaronrobb ... Upping. I'm experiencing this as well. Works in my local env and builds fine (Mac OSX), but bombs in production (Ubuntu).

Any clean fix on this?

@Patabugen
Copy link

Patabugen commented Feb 23, 2017

Rather than commenting out the .pipe(function line, a neater way to disable sourcemaps would be by changing the enabled.maps function to false.

I've done it this way, to make it clear why it's disabled and what to do when the bug is fixed:

  // Disable source maps when `--production`
  // maps: !argv.production,
  maps: false, // Disabled due to this bug: https://github.com/nodejs/help/issues/429

That said, I believe this is a bug with gulp-sourcemaps rather than nodejs so the issue should probably be moved there.

@araphiel
Copy link

araphiel commented Apr 18, 2017

@Patabugen @tfmccomas @aaronrobb

Ran into this issue using roots/sage 8.5.1 gulp set up with bootstrap-sass. I was able to get around this by rolling gulp-sass back to v2.3.2 .

Others also had similar issues

@QuintinS
Copy link

QuintinS commented May 7, 2017

+1

@hvalcourtSerdy
Copy link

It appears this may be related to sass/libsass#2312

@bmbsk
Copy link

bmbsk commented May 23, 2017

@araphiel 's solution worked for me :-)

@hvalcourtSerdy
Copy link

For node-sass the version 3.4.2 is working, but the bug is not fixed, it's only a temporary solution

@jcapozzi
Copy link

jcapozzi commented Nov 30, 2017

EDIT: this doesn't result to the same selector see below.

Google brought me here after searching for a solution for sass/libsass#2312 which is sadly locked so I can't comment there but maybe this will help someone else:

Adding a space after the & after getting the error fixed it for me.

Before:
&:hover { color: red; }

After:
& :hover { color: red; }

@araphiel
Copy link

araphiel commented Nov 30, 2017

@jcapozzi

Does it still process correctly as
.target:hover { color: red; }
& not
.target :hover { color: red; }

https://codepen.io/anon/pen/EbGVQd

@jcapozzi
Copy link

jcapozzi commented Dec 1, 2017

@araphiel

Correct you are, that doesn't compile to the same selector. I was so excited to see the error disappear I forgot test the result.

Attempt 2:

.parent { @at-root #{&}:hover { color: red; } }

Ugly but at least I don't have to move my nested css and once fixed a find-and-replace should work.

https://codepen.io/anon/pen/ooJVVr

@montik
Copy link

montik commented Jan 19, 2018

I also replaced & with #{"&"} in the mixin and now it seems to work fine.

Niklan added a commit to Niklan/Glisseo that referenced this issue Feb 17, 2018
- gulp-sass dependency was downgraded to 2.3.2 cuz of bug in mainstream 3.1.0 with sourcemaps and ampersand. @see nodejs/help#429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests