ngAnnotate - Warning: StringMap expected string key
Asked Answered
A

4

23

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?

Auriscope answered 31/8, 2017 at 11:39 Comment(0)
A
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.

Auriscope answered 31/8, 2017 at 11:39 Comment(2)
Thx, you saved me some debugging :) best solution IMHO is to build everything with babel, and use babel-plugin-angularjs-annotateRolling
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.Jill
L
24

Possible reasons:

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

Solutions:

  • function () {}
  • { value: value }
  • var
  • function (args)
  • function (defaultVar) { defaultVar = (defaultVar === undefined) ? false : defaultVar }
Longobard answered 6/2, 2020 at 7:16 Comment(1)
depending on where you use ... the other solution would be to use .concat()Bellarmine
L
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...

Lanilaniard answered 18/7, 2018 at 6:36 Comment(1)
Thank you! This was the root cause for me too.Rifle
E
2

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

// the following line broke the build
const { name, gender, yearOfBirth, occupation } = profile;
Equitation answered 27/5, 2022 at 10:44 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewNeruda

© 2022 - 2024 — McMap. All rights reserved.