Jshint: JSHint throws an error when including it as a requirejs module

Created on 21 Jan 2016  ·  5Comments  ·  Source: jshint/jshint

Hi,

As part of a POC I am developing, I have prepared a small sample that will allow my angular app to work with requirejs. Now I am planning to integrate JsHint. The only requirement is that there is no nodejs.

I have taken the js file from the dist folder of the release and loaded it as a require module. But when doing so, I get the following error
jshint_error

Uncaught TypeError: _.each is not a function

All the other modules that I have loaded through require are fine like bootstrap and angular. I have tried including underscore.js and load it before jshint but to no avail.

Is this a bug with jshint or am I doing something wrong. below is the code for my requirejs bootstrapping

require.config({
baseUrl: 'scripts',
paths: {
'jshint':'lib/jshint/jshint',
'angular': 'lib/angular/angular.min',
'angular-route': 'lib/angular/angular-route.min'

},
shim: {
    'app': {
        deps: ['jshint','angular', 'angular-route']
    },
    'angular-route': {
        deps: ['angular']
    }
}

});

require
(
[
'app'
],
function(app)
{
angular.bootstrap(document, ['app']);
}
);

Most helpful comment

Somehow the presence of requirejs (or maybe AMD in general) makes loading lodash fails.
It works in v2.6.3, but it starts to fail in v2.7.0

I have a sample showing it sample with v2.9.3. The error from Developer tools:

VM104 jshint.js:15777 
Uncaught TypeError: _.each is not a function
  require.14.lodash @ VM104 jshint.js:15777
  s @ VM104 jshint.js:6
  (anonymous function) @ VM104 jshint.js:6
  ...

In contrast,

Any idea?

All 5 comments

I would expect that underscore is not marked as a dependency of jshint. Also, modern jshint is using lodash, so there may be some compat issues with lodash, though i doubt it.

Just spitballin

I have faced the same issue... Any workarounds?

Somehow the presence of requirejs (or maybe AMD in general) makes loading lodash fails.
It works in v2.6.3, but it starts to fail in v2.7.0

I have a sample showing it sample with v2.9.3. The error from Developer tools:

VM104 jshint.js:15777 
Uncaught TypeError: _.each is not a function
  require.14.lodash @ VM104 jshint.js:15777
  s @ VM104 jshint.js:6
  (anonymous function) @ VM104 jshint.js:6
  ...

In contrast,

Any idea?

In SystemJS, you need to specify the format as global (as opposed to AMD or CommonJS) in meta as per https://github.com/systemjs/systemjs/blob/master/docs/module-formats.md#globals

SystemJS.config({
    baseURL: './js',
    defaultJSExtensions: true,
    paths: {
        'jquery': './js/vendor/jquery/jquery-3.2.1.min.js',
        // ...
    },
    meta: {
        './js/vendor/codemirror/addon/lint/jshint.js': { format: 'global' }
    }
});
SystemJS.import('./js/app.js').then(function (app) {
    // ...
})

Note that Webpack automatically detects the format.

Hopefully this will help with requireJS.

Somehow the presence of requirejs (or maybe AMD in general) makes loading lodash fails.
It works in v2.6.3, but it starts to fail in v2.7.0

I have a sample showing it sample with v2.9.3. The error from Developer tools:

VM104 jshint.js:15777 
Uncaught TypeError: _.each is not a function
  require.14.lodash @ VM104 jshint.js:15777
  s @ VM104 jshint.js:6
  (anonymous function) @ VM104 jshint.js:6
  ...

In contrast,

Any idea?

After 2.6.3 it changed from Underscore to Lodash.
Check the 'var _ = require("underscore");' in 2.6.3 and 'var _ = require("lodash");' in 2.12.10

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Guichaguri picture Guichaguri  ·  8Comments

ghost picture ghost  ·  3Comments

nzakas picture nzakas  ·  10Comments

stefanuddenberg picture stefanuddenberg  ·  7Comments

NemoStein picture NemoStein  ·  7Comments