22

I get this warning when using Grunt and grunt-ng-annotate.

There is no reference in the warning to where the error is in the file, which makes debugging it hard.

Any ideas?

iss42
  • 2,720
  • 3
  • 21
  • 37

4 Answers4

38

The issue turned out to be use of ES6 notation, in this case arrow functions (=>), default parameters and let.

I haven't looked in detail as to why ngAnnotate doesn't support this.

To find where the issues were I overrode the ngAnnotate warning with grunt switch --force and later in the build uglify complained about the ES6 syntax with more detail.

iss42
  • 2,720
  • 3
  • 21
  • 37
  • 6
    Thx, you saved me some debugging :) best solution IMHO is to build everything with babel, and use `babel-plugin-angularjs-annotate` – Bruno Schäpper Nov 30 '17 at 14:46
  • To find the line number with the problem, use `--force` to push past ng-annotate. `uglify` will complain later, with an actual line number in the .tmp source code. – Sam Barnum Apr 23 '21 at 23:26
18

Possible reasons:

  • () => {}
  • { value }
  • let
  • function (...args)
  • function (defaultVar = false)

Solutions:

  • function () {}
  • { value: value }
  • var
  • function (args)
  • function (defaultVar) { defaultVar = (defaultVar === undefined) ? false : defaultVar }
13

I also faced the same problem but in my case, there was a different issue.

One of our team members has initialized function parameter to some default value. Something like the following.

$scope.functionName = function(defaultVar = false){ 
    //some code 
}

and in my gulp script, there was a line

.pipe(plugins.if(release, plugins.ngAnnotate()))

So when I have removed this line the build script automatically printed the error in console pointing to the exact file and line number where the error was.

Finally, I was able to solve it by removing that variable initialization code.

Hope this will help someone...

Mr. Noddy
  • 1,530
  • 2
  • 16
  • 45
1

I also faced a similar issue caused by a destructuring assignment:

// the following line broke the build
const { name, gender, yearOfBirth, occupation } = profile;
Xava
  • 29
  • 3
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31877984) – maowtm Jun 02 '22 at 18:39