JavaScript - Gulp / Browserify: SyntaxError: Unexpected token

For some reason my browserifyand gulpstopped working. For example, here is my gulp jsscript for linking my javascript.

gulp.task('js', function() {
    gulp.src('src/js/*.js')
        .pipe(plumber())
        .pipe(gulp.dest('js'));
    return browserify('./src/js/main', { debug: true })
    .bundle()
    .pipe(source('bundle.js'))
/*    .pipe(streamify(uglify()))*/
    .pipe(gulp.dest('.'))
    .pipe(notify({ message: 'JavaScript has been bundled with Browserify!'}));
    // .pipe(livereload());
});

and here main.js:

var ajaxChng = require('./ajax-changelog');
ajaxChng();

and inside src/js/ajax-changelog.js:

module.exports = {
    console.log('Hello World');
};

But when I do gulp js, I get:

λ gulp js
[19:11:50] Using gulpfile c:\wamp\www\osrsmap\gulpfile.js
[19:11:50] Starting 'js'...

events.js:85
      throw er; // Unhandled 'error' event
            ^
SyntaxError: Unexpected token

... what am I doing wrong?

+4
source share
1 answer

Wait ... this is invalid javascript:

module.exports = {
    console.log('Hello World');
};

Did you mean this?

module.exports = function () {
    console.log('Hello World');
};
+10
source

All Articles