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.

init({ loadMaps: true }) does not remove sourcemaps added earlier in the same pipeline

See original GitHub issue

If a sourcemap is written, and then subsequently loaded and written again in the same pipeline, then the final output contains both sourcemaps.

For example, given the following input file (test.es6.js):

let value = 'Test Value';

console.log(`value: ${ value }`);

When running the following Gulp script:

import gulp from 'gulp';
import gulpBabel from 'gulp-babel';
import gulpRename from 'gulp-rename';
import gulpSourcemaps from 'gulp-sourcemaps';

gulp.task('test.es5.js', [], () => {
    return gulp.src('test.es6.js')
        .pipe(gulpSourcemaps.init())
        .pipe(gulpBabel())
        .pipe(gulpRename('test.es5.js'))
        .pipe(gulpSourcemaps.write())
        .pipe(gulpSourcemaps.init({ loadMaps: true }))
        .pipe(gulpSourcemaps.write())
        .pipe(gulp.dest('.'))
});

Then the following output is produced (test.es5.js):

'use strict';

var value = 'Test Value';

console.log('value: ' + value);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxRQUFRLFlBQVo7O0FBRUEsUUFBUSxHQUFSLGFBQXVCLEtBQXZCIiwiZmlsZSI6InRlc3QuZXM1LmpzIiwic291cmNlc0NvbnRlbnQiOlsibGV0IHZhbHVlID0gJ1Rlc3QgVmFsdWUnO1xuXG5jb25zb2xlLmxvZyhgdmFsdWU6ICR7IHZhbHVlIH1gKTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxRQUFRLFlBQVo7O0FBRUEsUUFBUSxHQUFSLGFBQXVCLEtBQXZCIiwiZmlsZSI6InRlc3QuZXM1LmpzIiwic291cmNlc0NvbnRlbnQiOlsibGV0IHZhbHVlID0gJ1Rlc3QgVmFsdWUnO1xuXG5jb25zb2xlLmxvZyhgdmFsdWU6ICR7IHZhbHVlIH1gKTsiXSwic291cmNlUm9vdCI6Ii9zb3VyY2UvIn0=

If the pipeline is separated into two stages, with the file being output via gulp.dest() after the first sourcemap is written and then a new pipeline is created via gulp.src(), then the first sourcemap is removed as expected:

'use strict';

var value = 'Test Value';

console.log('value: ' + value);


//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxRQUFRLFlBQVo7O0FBRUEsUUFBUSxHQUFSLGFBQXVCLEtBQXZCIiwiZmlsZSI6InRlc3QuZXM1LnN0ZXAtMi5qcyIsInNvdXJjZXNDb250ZW50IjpbImxldCB2YWx1ZSA9ICdUZXN0IFZhbHVlJztcblxuY29uc29sZS5sb2coYHZhbHVlOiAkeyB2YWx1ZSB9YCk7Il0sInNvdXJjZVJvb3QiOiIvc291cmNlLyJ9

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:1
  • Comments:12

github_iconTop GitHub Comments

3reactions
otakustaycommented, Dec 20, 2016

I have the same problem:

rollup(merge(ROLLUP_CONFIG, {entry: './src/index.js'}))
            .pipe(source('index.js', './src/*'))
            .pipe(buffer())
            .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(sourcemaps.write('./map'))
            .pipe(gulp.dest('.'));

This ended with a map/index.js.map file along with an inline sourcemap so the external .map file would never be used.

Another task includes an uglify step and it output the .map file and a correct sourceMappingURL

rollup(merge(ROLLUP_CONFIG, {entry: './src/index.js'}))
            .pipe(source('index.js', './src/*'))
            .pipe(buffer())
            .pipe(sourcemaps.init({loadMaps: true}))
            .pipe(uglify(UGLIFY_OPTIONS))
            .pipe(rename({suffix: '.min'}))
            .pipe(sourcemaps.write('./map'))
            .pipe(gulp.dest('.'));

The essential difference is the uglify step

1reaction
wvankuiperscommented, Dec 28, 2016

Use the previous release 2.2.0 or 1.9.0

In my case downgrading to 2.2.0 resolved this issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove Source Mapping with Gulp - Stack Overflow
task('jquery', function () { gulp.src(paths.jquerySrc) .pipe(sourcemaps.init({loadMaps: true})) .
Read more >
gulp-relative-sourcemaps-source - npm
Converts paths to files with the sourcemaps content to be relative to the source file directory.. Latest version: 1.1.1, last published: 4 ...
Read more >
4 Reasons Why Your Source Maps are Broken - Sentry Blog
This likely means that your source map doesn't contain or link to your original source files. Without your original source files, you're still ......
Read more >
Documentation - Gulp - TypeScript
Before we get to Browserify, let's build our code out and add modules to the mix. This is the structure you're more likely...
Read more >
Pinpoint Those Pesky Minified Javascript Errors With Sentry
One way to tackle this is to set up a VPN so these are not accessible anywhere ... writes source maps .pipe(sourcemaps.init({ loadMaps:...
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