gulp-terser icon indicating copy to clipboard operation
gulp-terser copied to clipboard

`module: true` Causes "SyntaxError in plugin 'terser': Unexpected token eof (undefined)"

Open jeremy-harnois opened this issue 4 years ago • 5 comments

Where Module.js is an ES6 module,

gulp.src('Module.js')
    .pipe(gulpTerser({module: true}))
    .pipe(gulp.dest('public/js'))

results in

SyntaxError in plugin "terser"
Message:
    Unexpected token: eof (undefined)
Details:
    filename: 0
    ...

while

gulp.src('script.js')
    .pipe(gulpTerser())
    .pipe(gulp.dest('public/js'))

does not.

Upgrading terser to latest (5.5.1) appears to resolve.

jeremy-harnois avatar Jan 13 '21 06:01 jeremy-harnois

You can try to configure Terser's ecma configuration, I think this error is caused by js syntax.

duan602728596 avatar Jan 13 '21 06:01 duan602728596

Still not work :

.pipe(terser({ecma: 2015}))

arabine avatar Jan 19 '21 10:01 arabine

Still not work :

.pipe(terser({ecma: 2015}))

Does your code contain versions above 2015, and you have not compiled the code?

duan602728596 avatar Jan 19 '21 10:01 duan602728596

You can try to configure Terser's ecma configuration, I think this error is caused by js syntax.

The same Gulp task was working prior, and upgrading Terser solved the issue without changing the source script, so I don't believe it's a syntax error.

There's some conversation about this in Terser issues. I'm not using Ember, but it appears some package changes elsewhere caused issues in Terser. I suspect they resolved those, which is likely why upgrading Terser in this package fixed this issue for me.

jeremy-harnois avatar Jan 20 '21 18:01 jeremy-harnois

Still not work : .pipe(terser({ecma: 2015}))

Does your code contain versions above 2015, and you have not compiled the code?

Maybe! But my problem was elsewhere (a gulp task that remove all console.log resulting bad code). I end up using Terser directly from the command line. Did not tried gulp-terser after that sorry :(

arabine avatar Jan 21 '21 10:01 arabine