24

I'm using the underscore library.

I get this when running jshint:

[L38:C38] W117: '_' is not defined.
      var approvedAndRequstedCount = _.countBy(products, function(obj) {

Warning: Task "jshint:all" failed. Use --force to continue.

This is my config file:

{
  "node": true,
  "browser": true,
  "esnext": true,
  "bitwise": true,
  "camelcase": false,
  "curly": true,
  "eqeqeq": true,
  "immed": true,
  "indent": 2,
  "latedef": true,
  "newcap": true,
  "noarg": true,
  "quotmark": "single",
  "regexp": true,
  "undef": true,
  "unused": true,
  "strict": true,
  "trailing": true,
  "smarttabs": true,
  "globals": {
    "angular": false
  }
}

I guess it's something with the globals option? I tried to add "_": false but no luck. Any ideas?

4
  • 2
    "_": false works for me (in globals). Mar 4, 2014 at 16:07
  • Oh! Yes, I also have a "-W117": true on the main configuration object. Mar 4, 2014 at 16:08
  • W117: true solved the issue! Thx. I'll approve if you post an answer with a short explanation.
    – Joe
    Mar 4, 2014 at 16:17
  • I'm not sure turning off W117 is a good thing. But it is a workaround. Probably not good enough for an answer. Mar 4, 2014 at 16:21

1 Answer 1

47

I had this issue as well.

I installed underscore: bower install -save underscore and it worked fine in the code. Unfortunately jshint was not finding that reference. You must tell jshint about your global variables in configuration file like .jshintrc:

{
  …
  "globals": {
    "angular": false,
    "_": false
  }
}

If you continue to have this issue you need to make sure that underscore is included when jshint is executed. I would not recommend setting -W117 to true. Squelching those errors might lead to more bugs.

1
  • 1
    This also applies when using lodash. It worked for me.
    – Kent Bull
    Feb 1, 2016 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.