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

Issue with sourcemaps (later transformations) #354

Open
glen-84 opened this issue Sep 30, 2015 · 21 comments
Open

Issue with sourcemaps (later transformations) #354

glen-84 opened this issue Sep 30, 2015 · 21 comments

Comments

@glen-84
Copy link

glen-84 commented Sep 30, 2015

Please refer to gulp-sourcemaps/gulp-sourcemaps#124.

I am experiencing exactly the same problem using the following Gulp task (ES2015):

gulp.task("build-css", () => {
    return gulp.src(cssSrc)
        .pipe(newer({
            dest: cssDest,
            ext: ".css"
        }))
        .pipe(sourcemaps.init({debug: true}))
        .pipe(sass({
            // See: https://github.com/sass/node-sass/issues/957
            //outputStyle: "compressed"
            outputStyle: "expanded"
        }).on("error", sass.logError))
        .pipe(autoprefixer({
            // Default for Browserslist (https://github.com/ai/browserslist) @ 2015/09/18
            browsers: ["> 1%", "last 2 versions", "Firefox ESR"]
        }))
        .pipe(sourcemaps.write(".", {debug: true}))
        .pipe(gulp.dest(cssDest));
});

Could it be the same thing described in this comment?

Versions:

  • OS: Windows 7 (x64)
  • Node: 4.1.1
  • NPM: 3.3.4
  • gulp-sourcemaps@1.6.0
  • gulp-sass@2.1.0-beta
  • gulp-autoprefixer@3.0.2
@xzyfer
Copy link
Collaborator

xzyfer commented Oct 1, 2015

@glen-84 please create a small github repo with a working gulp task that shows this issue in action.
There is simply too much noise in these issue to get a clear idea of what is happening. We need to see this issue in action to begin debugging it.

@glen-84
Copy link
Author

glen-84 commented Oct 1, 2015

https://github.com/glen-84/gulp-sass-sourcemaps-issue

$ npm install
$ gulp

Notes:

  • The issue does not occur when the file is in the root of the src folder (test.scss).
  • To view the working CSS, uncomment the first link element in dist/index.html.
  • The issue occurs with the src/app/styles/test2.scss file.
  • Look at the button element btn class for an example, it should point to _buttons.scss, not test2.css.

Let me know if you need anything else.

Thanks.

@xzyfer
Copy link
Collaborator

xzyfer commented Oct 5, 2015

Sorry for the delay, I will take a look a look at this shortly.

@xzyfer
Copy link
Collaborator

xzyfer commented Oct 5, 2015

@glen-84 in the mean time, are you able to create a failing test case?

@xzyfer
Copy link
Collaborator

xzyfer commented Oct 5, 2015

Note to self, this could be related to sass/node-sass#1194

@glen-84
Copy link
Author

glen-84 commented Oct 5, 2015

@glen-84 in the mean time, are you able to create a failing test case?

That was my failing test case. 😁

But seriously, I don't know much about unit testing JavaScript. 😞

@glen-84
Copy link
Author

glen-84 commented Oct 12, 2015

@xzyfer Did you find anything?

@xzyfer
Copy link
Collaborator

xzyfer commented Oct 12, 2015

@glen-84 I have not had time to look into this. I'm busy until LibSass 3.3.0 ships. Sorry.

@mariusGundersen
Copy link

This could be related to mozilla/source-map#216

@glen-84
Copy link
Author

glen-84 commented Oct 26, 2015

@mariusGundersen I don't think so, it doesn't work in Chrome either.

@clee704
Copy link

clee704 commented Oct 28, 2015

Hi guys, here is a similar problem.

Reproduction scenario:

git clone https://github.com/clee704/gulp-autoprefixer-test.git
cd gulp-autoprefixer-test
npm install
git checkout error
gulp css  # Unhandled 'error' event
git checkout lost
gulp css
head -c 200 build/css/app.css.map  # "sources" array is incomplete
git checkout works
gulp css
head -c 200 build/css/app.css.map  # correct "sources"

It works if gulp-autoprefixer is not used. It seems the source map object returned by gulp-sass is not standard complient.

@saschaeggi
Copy link

I also experience a problem with gulp-sass 2.1.0 and gulp-sourcemaps 1.6.0.
It always shows the highest level in the sass code and not the deepest one.

@backflip
Copy link
Contributor

The last version where the tests we specified in https://github.com/unic/estatico/tree/develop/test/css still work (clone the repo and run npm test) is 2.0.3 in combination with node-sass <= 3.3.3.

  • Updating gulp-sass to 2.0.4 or 2.1.0 (and keeping node-sass at 3.3.3) leads to an incomplete sources array.
  • Updating node-sass to 3.4.1 (and keeping gulp-sass at 2.0.3) breaks the line mapping.
  • Updating both breaks every aspect. :)

@glen-84
Copy link
Author

glen-84 commented Dec 11, 2015

@xzyfer Now that LibSass 3.3.0 has shipped, when do you think that you might have time to look into this?

@xzyfer
Copy link
Collaborator

xzyfer commented Dec 11, 2015

Unfortunately no one has submitted a test case showing exactly what sass is
required to break source maps. We know there are issue but source maps
complicated and with very specific test cases there isn't much we can do.
On 11 Dec 2015 9:10 pm, "Glen" notifications@github.com wrote:

@xzyfer https://github.com/xzyfer Now that LibSass 3.3.0 has shipped,
when do you think that you might have time to look into this?


Reply to this email directly or view it on GitHub
#354 (comment)
.

@glen-84
Copy link
Author

glen-84 commented Dec 11, 2015

@xzyfer I don't understand. I took the time to create a very simple repo that clearly shows the issue (see this comment).

@clee704 and @backflip have also supplied test cases, and @backflip has even specified what breaks and in which versions it breaks.

What else could you need? 😕

@backflip
Copy link
Contributor

backflip commented Oct 9, 2016

Switching from gulp-autoprefixer to gulp-postcss (as suggested in sindresorhus/gulp-autoprefixer#66 (comment)) seems to "fix" the incomplete sources. However, line-numbers are still off when nesting selectors in SCSS (pointing everything to the root selector's line). Same for introducing an intermediate sourcemap write as suggested in gulp-sourcemaps/gulp-sourcemaps#60 (comment)

@backflip
Copy link
Contributor

backflip commented Oct 9, 2016

@xzyfer, would you mind having another look at this?

@backflip
Copy link
Contributor

backflip commented Nov 3, 2016

Let's wait for sass/libsass#2216 to land in node-sass, it certainly sounds promising.

@glen-84
Copy link
Author

glen-84 commented Feb 6, 2017

I just updated my test repo, and the problem is still there.

@bonovski
Copy link

bonovski commented Feb 7, 2018

My issue was that the sourcemap was pointing to the wrong files in developer tools.

To get everything working the way it should you have to pipe like this:

  1. gulp-sass (use anything but compressed, compressing before all other pipes will mess with sourcemaps)
  2. gulp-autoprefixer
  3. cssnano (or the uglifier of your choice)
gulp.task( 'styles', function() {
	gulp.src( [ styleSRC ] )
		.pipe( sourcemaps.init() )
		.pipe( sass({
			includePaths: [ foundation, motionUI, datepicker ],
			errLogToConsole: true,
			outputStyle: 'compact'
		}) )
		.on( 'error', notify.onError( function (error) {
			return 'An error occurred while compiling sass.\nLook in the console for details.\n' + error;
		} ) )
		.pipe( autoprefixer({ browsers: [ 'last 3 versions', '> 5%', 'Firefox ESR' ] }) )
		.pipe( postcss( [ cssnano() ] ))
		.pipe( rename( { suffix: '.min' } ) )
		.pipe( sourcemaps.write( mapURL ) )
		.pipe( gulp.dest( styleURL ) )
		.pipe( browserSync.stream() );
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants