gulp-strip-comments icon indicating copy to clipboard operation
gulp-strip-comments copied to clipboard

Unespected token ILLEGAL - esprima.js

Open Alecell opened this issue 7 years ago • 10 comments

C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:3391 throw error; ^ Error: Line 1: Unexpected token ILLEGAL at ErrorHandler.constructError (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:3396:22) at ErrorHandler.createError (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:3414:27) at ErrorHandler.throwError (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:3422:21) at Scanner.throwUnexpectedToken (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:3505:28) at Scanner.scanPunctuator (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:4026:19) at Scanner.lex (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:4628:22) at Tokenizer.getNextToken (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:6366:43) at Object.tokenize (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\node_modules\esprima\dist\esprima.js:136:36) at Object.parseRegEx (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\lib\utils.js:37:13) at parser (C:\wamp\www\reiPallet\node_modules\gulp-strip-comments\node_modules\decomment\lib\parser.js:34:27)

I get this error message when try to run the gulp task, I tryed to solve the error but it was unsuccessful.

Alecell avatar Mar 28 '17 19:03 Alecell

So you must be sending an invalid javascript file into it.

vitaly-t avatar Mar 28 '17 19:03 vitaly-t

I just remove all the .js files in my project and get the same error.

Alecell avatar Apr 03 '17 14:04 Alecell

  1. Find which file + extension it complains about
  2. Post either the while file here or the line where it complains
  3. Post which decomment method you are using to process the file

Then it will be possible to assist you further.

vitaly-t avatar Apr 03 '17 16:04 vitaly-t

Same issue, there is a problem when you specify wildcards such as '/**/*' in the gulp.src preceding the strip task.

What happens is that the file discovery in the through.obj call goes up a directory and loads files from there.

Given this file structure

root
    src\
    dest\
    gulpfile.js

Using this gulp command

return gulp.src('dest/*/**''] )
    .pipe(strip())
    .pipe(gulp.dest('dest'));

Will actually load files from 'root/**' and not just from 'root/dest/'

sverrirs avatar Sep 01 '17 10:09 sverrirs

@sverrirs try gulp-decomment instead, which does the same ;)

vitaly-t avatar Sep 21 '17 09:09 vitaly-t

I solved this issue by rewriting division statements.

Original:

var lng = _.reduce(userList, function(memo, userElement) {
    if (userElement.location.coordinates[0] !== 0) {
        j++;
        return memo + userElement.location.coordinates[0];
    }
    else
        return memo;
}, 0) / (j === 0 ? 1 : j);

Fix:

var lng = _.reduce(userList, function(memo, userElement) {
    if (userElement.location.coordinates[0] !== 0) {
        j++;
        return memo + userElement.location.coordinates[0];
    }
    else
        return memo;
}, 0);

lng = lng / (j === 0 ? 1 : j);

BuffMcBigHuge avatar Dec 13 '17 22:12 BuffMcBigHuge

@sverrirs try gulp-decomment instead, which does the same ;)

Produces exactly the same error though

jessedegans avatar Jan 28 '22 20:01 jessedegans

I am having this issue with private class members - for both gulp-decomment and gulp-strip-comments. Perhaps the parser(s) used by these libs are not up to date with the latest syntax.

Mattnificent avatar Oct 03 '23 17:10 Mattnificent

Nevermind those are a Node.js 12 language feature, and I'm using version 11!

Mattnificent avatar Oct 03 '23 18:10 Mattnificent

Well, updating node.js didn't fix the issue - but my error message looks nicer now

Node version:
16.14.0

[14:17:22] Error in plugin "gulp-strip-comments"
Message:
    Line 4773: Unexpected token ILLEGAL
Details:
    index: 308968
    lineNumber: 4773
    description: Unexpected token ILLEGAL
    fileName: C:\my\file\path.js
Process terminated with code 1.

Mattnificent avatar Oct 03 '23 18:10 Mattnificent