Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript - Gulp/Browserify: SyntaxError: Unexpected token

For whatever reason, my browserify and gulp stopped working. For example, here's my gulp js script to bundle 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 is main.js:

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

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

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?

like image 580
Zeng Cheng Avatar asked Dec 24 '22 21:12

Zeng Cheng


1 Answers

Wait... this is not valid javascript:

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

Maybe you meant this?

module.exports = function () {
    console.log('Hello World');
};
like image 186
axelduch Avatar answered Dec 28 '22 07:12

axelduch