gulp-uglify: Uglify not working with gulp-sourcemaps

When I try and uglify my code without concatenating it and then generate source maps I get an error message like:

gulp-sourcemap-write: source file not found:C:\Rob\Dropbox\Repos\gulpTest\?

my gulp task looks like this

gulp.task('js', function () {
    return gulp.src('app.js')
        .pipe(sourcemaps.init())
        .pipe(uglify())
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('build'));
});

I’m using the following versions of npm modules

  "dependencies": {
    "gulp": "3.8.8",
    "gulp-uglify": "1.0.1",
    "gulp-sourcemaps": "1.1.5"
  }

There is a zipped up version of the project here https://dl.dropboxusercontent.com/u/20066539/Forum Links/Other/gulpTest.zip

This issue is related to https://github.com/floridoo/gulp-sourcemaps/issues/34

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 48 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I’m having the same problem. It seems that concat somehow fixes it, so if you use…

gulp.src("app.js")
  .pipe(sourcemaps.init())
  .pipe(concat("app.js"))
  .pipe(uglify())
  .pipe(sourcemaps.write("dist"))
  .pipe(gulp.dest("dist"));

…everything is working fine. However, without the line that applies concat you get an invalid source map ("sources":["?"], "sourcesContent":[null])

I have several files I do not want to concatenate. As a workaround I could just put each single file in a separate gulp.src() statement, then apply the pipe operations (including concat for that single file, which normally should be a noop, but isn’t here as it fixes the bug) and at the end merge them together, but that would not be very pretty. This should work without concat and with multiple input files.

Any ideas?