angularjsgulpbowergulp-uglifymain-bower-files

Gulp: SyntaxError: Unexpected end of JSON input


I have an AngularJS app, for which I use bower, npm and gulp. This code was working few days ago, not sure why but I'm getting the below when I do the gulp command:

gulp minifycss;

Error:

 SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at module.exports (..\node_modules\main-bower-files\lib\index.js:48:43)
at Gulp.<anonymous> (..\gulpfile.js:72:33)
at module.exports (..\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (..\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (..\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (..\node_modules\orchestrator\index.js:134:8)
at C:\Users\bgi5\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)

Gulp Code:

var cleanCss = require('gulp-clean-css'),  
filter = require('gulp-filter'),
concat = require('gulp-concat'),
merge = require('merge-stream'),
bowerFiles = require('main-bower-files');
var config = {
paths: {
    src: './src',
    build: './build',
    bower: './bower_components'
}
};
gulp.task('minifyCss', function () {
var v= gulp.src(bowerFiles())
    .pipe(filter(['**/*.css']))
    .pipe(concat('v.css'))
    .pipe(cleanCss({debug: true}))
    .pipe(gulp.dest(config.paths.build + '/styles'));

var a= gulp.src(config.paths.src + '/**/*.css')
    .pipe(concat('a.css'))
    .pipe(cleanCss({debug: true}))
    .pipe(gulp.dest(config.paths.build + '/styles'));

return merge(v, a);
});

Solution

  • This is caused by the variable bowerFiles in your code.

    bowerFiles = require('main-bower-files');

    For some reason it is not finding the required css files from the bower packages you have installed. As the error says something about JSON, I guess there is a problem with your bower configuration file .bowerrc. Double check bower directory it is pointing to is correct or not. Check this link for more info on .bowerrc file.