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

gulp-sourcemap-write: source file not found: /absolutePathToProject/scripts/? #37

Closed
dcleao opened this issue Sep 20, 2014 · 19 comments
Closed

Comments

@dcleao
Copy link

dcleao commented Sep 20, 2014

Hi,

this is happening to me whenever a glob doesn't match any file.

I do have some file paths that are configured in general, for cases where there might be a file in a certain directory.
Is this a bug? Can it be silenced (without doing it to all logging)?

@koistya
Copy link

koistya commented Sep 22, 2014

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

gulp.task('styles', function () {
  return gulp.src('src/styles/bootstrap.less')
    .pipe($.sourcemaps.init())
    .pipe($.less())
    .pipe($.autoprefixer())
    .pipe($.sourcemaps.write());
    .pipe(gulp.dest('./build/css'));
});
$ gulp styles
[11:13:47] Using gulpfile gulpfile.js
[11:13:47] Starting 'styles'...
gulp-sourcemap-write: source file not found: src\styles\bootstrap.css
[11:13:49] Finished 'styles' after 1.97 s

gulp-sourcemaps 1.2.2, gulp-less 1.3.6, gulp-autoprefixer 1.0.1, OS: Windows

@floridoo
Copy link
Member

That error message means that:

  • sourcesContent for one of the files is missing
  • sourcemaps.write() tries to fix that by loading the content of the source file, but it can not find it (probably because the path in sources is incorrect)

Both are probably issues of either gulp-less or gulp-autoprefixer.

@dcleao
Copy link
Author

dcleao commented Sep 22, 2014

The files do not exist. It's not an error...
The files exist in some projects and don't in others.
The gulp file is developed for the general case.
In that sense, it's not an error, or something I forgot to configure...
It's not a problem of either gulp-less or autoprefixer.
As far as I have noticed, other gulp plugins don't complain of receiving empty globs.
Yours does.

@philipwalton
Copy link

This is happening to me as well, but for files that are definitely there:

gulp.src('./src/script.js')
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dest'));

The following is logged:

gulp-sourcemap-write: source file not found:/path/to/project/src/?

Strangely, if I add in an additional plugin to concat the file (which, since it's just one file should theoretically do nothing) everything works as expected:

gulp.src('./src/script.js')
    .pipe(sourcemaps.init())
    .pipe(concat('script.js'))
    .pipe(uglify())
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('./dest'));

I'm running version 1.2.4 and the latest version of all my dependencies.

@ghost
Copy link

ghost commented Oct 22, 2014

I'm also having an issue. I have an array with files it needs to uglify and concat. These files are in 2 different directories. One is a bower directory and another is a theme/js directory.

It looks like the sourcemaps plugin is messing up the locations.

This is the error that I get:
gulp-sourcemap-write: source file not found: xxx\bower_components\jquery\dist\global.js

Well, the global is the one inside the theme folder. Not the bower folder as you can see in the array:
[ './bower_components/jquery/dist/jquery.js',
'./bower_components/bootstrap/dist/js/bootstrap.js',
'./public_html/wp-content/themes/xxx/assets/js/disable-noconflict.js',
'./public_html/wp-content/themes/xxx/assets/js/global.js' ]

So it does not keep track of the directory the files are in.

The concatting and uglifying itself works like a charm. It's the sourcemapping that goes wrong.
I did not have this error in older versions, it used to work fine a couple of months ago.

@floridoo
Copy link
Member

@philipwalton the "?" seems to be coming from gulp-uglify, which does not pass on the source list correctly when it is the first plugin
@JohnHeroHD hard to help you without more information, e.g. your gulpfile (the relevant part)

@ghost
Copy link

ghost commented Oct 22, 2014

@floridoo

Sorry. Here you go:

var gulp = require('gulp');

var defaultTasks = ['watch'];

var rename      = require('gulp-rename');
var uglify      = require('gulp-uglify');
var concat      = require('gulp-concat');
var gulpIgnore  = require('gulp-ignore');
var plumber     = require('gulp-plumber');
var sourcemaps = require('gulp-sourcemaps');

var root = './public_html/wp-content/themes/xxx';
var dist_path = root + '/assets/dist';
var js_plugin_path = './bower_components/';
var js_script_path = root + '/assets/js/';

var js_files = [
    js_plugin_path + 'jquery/dist/jquery.js',
    js_plugin_path + 'bootstrap/dist/js/bootstrap.js',

    js_script_path + 'disable-noconflict.js',
    js_script_path + 'global.js'
];

/* process the js files and make it a minified js */
gulp.task('js', function() {
    gulp.src(js_files)
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(concat('main.js'))
        .pipe(uglify())
        .pipe(rename({suffix: '.min'}))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest(dist_path));
});

gulp.task('build', function() {
    gulp.start('js');
});

/* look for changes */
gulp.task('watch', function() {
    gulp.watch(root + '/assets/js/*.js', ['js']);
});

/* run the watch task */
gulp.task('default', ['watch'])

And the packages:

{
  "devDependencies": {
    "gulp": "^3.6.2",
    "gulp-concat": "^2.2.0",
    "gulp-ignore": "^1.0.1",
    "gulp-plumber": "~0.6.3",
    "gulp-rename": "^1.2.0",
    "gulp-uglify": "^0.3.1",
    "gulp-sourcemaps": "~1.2.4"
  }
}

@floridoo
Copy link
Member

@JohnHeroHD: You get this error because one of the plugins looses the source content. gulp-sourcemaps tries to correct this by loading the content from the file, but the path to the file gets messed up somewhere too, so it cannot load it.

@ghost
Copy link

ghost commented Oct 22, 2014

Thanks for the quick response. I do not completely understand it. But most importantly, how can I solve this?

@ghost
Copy link

ghost commented Oct 22, 2014

I managed to fix it by updated all the dependencies to their latest versions. My new file looks like this now:

{
  "devDependencies": {
    "gulp": "3.8.9",
    "gulp-concat": "2.4.1",
    "gulp-ignore": "1.2.0",
    "gulp-plumber": "0.6.5",
    "gulp-rename": "1.2.0",
    "gulp-uglify": "1.0.1",
    "gulp-sourcemaps": "1.2.4"
  }
}

Hope this might help someone else.

@koistya
Copy link

koistya commented Oct 22, 2014

For example, the gulp-less plugin changes style.less filename to style.css, which prevents gulp-sourcemaps from working. What would be the right spot to fix this issue?

@floridoo
Copy link
Member

@koistya Why would changing the file name prevent gulp-sourcemaps from working?

@koistya
Copy link

koistya commented Oct 22, 2014

gulp.task('styles', function () {
  return gulp.src('styles/style.less')
    .pipe($.sourcemaps.init())
    .pipe($.less())
    .pipe($.autoprefixer())
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('build/css'));
});

Here is what it prints to the console:

[20:39:45] Starting 'styles'...
gulp-sourcemap-write: source file not found:C:\Projects\demo\styles\style.css
[20:39:49] Finished 'styles' after 4.02 s

@floridoo
Copy link
Member

@koistya one of the plugins in your chain seems to put a wrong source file reference into the source map (style.css)

@koistya
Copy link

koistya commented Oct 22, 2014

There is just gulp-less and gulp-autoprefixer

@nirazul
Copy link

nirazul commented Oct 28, 2014

This is happening to me when a file loaded from a web resource is present, in my case icomoon:
@import (less) url("http://i.icomoon.io/public/pathToMyProject/style.css");

@RadValentin
Copy link

@koistya I can confirm that this happens on my machine as well with gulp-less and gulp-autoprefixer though the sourcemaps themselves seem to work just fine. From what I gather there seems to be a problem with the way gulp-autoprefixer handles sourcemaps, see this PR sindresorhus/gulp-autoprefixer#3

Unfortunaltely no progress has been made so far, it sure would be awesome if this got fixed, @floridoo would you mind looking into this some more? Pretty please? 😄

@demisx
Copy link

demisx commented Oct 31, 2014

I believe the issue causing the "source file not found" error is usually in one of the plugins that precede .pipe(sourcemaps.write()) call. These plugins need to properly set 1) file.base property and 2) sourceMap.sources[i] property with a correct relative path, so it can properly be resolved against the former in https://github.com/floridoo/gulp-sourcemaps/blob/47300b454000e09ade0b79478a5ae320e78fb6d9/index.js#L183.

I don't think this has anything to do with the gulp-sourcemapsplugin itself, since it's trying to load the file contents from what was given to it.

@manubo
Copy link

manubo commented Nov 5, 2014

I had the same problem, the following fix in the UglifyJS2 package solved my problem: https://github.com/mishoo/UglifyJS2/pull/577/files

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

8 participants