Node/NPM/Grunt failing on jscs (grunt-jscs)
Asked Answered
E

3

7

I have a grunt task that runs JSCS on a javascript code base and it was working until it came time to integrate with the build server which is using latest, stable versions of grunt, npm/node.

This all ran fine under npm 1.XX.X but after i upgraded to 2.XX.X it broke. I tried latest, 3.XX.X, and that failed in the same fashion as 2.XX.X.

I assume the pertinent parts needed are the

the cli output:

$ node -v
v5.2.0

$ npm -v
3.3.12

$ grunt --version
grunt-cli v0.1.13
grunt v0.4.5

$ grunt jscs
Loading "jscs.js" tasks...ERROR
>> TypeError: fn.call is not a function
Warning: Task "jscs" not found. Use --force to continue.

Aborted due to warnings.

package.json:

{
"name": "Javascript",
  "version": "1.0.0",
  "private": true,
  "devDependencies": {
    "grunt": "~0.4.5",
    "matchdep": "^0.3.0",
    "grunt-contrib-watch": "~0.6.1",
    "grunt-express": "~1.4.1",
    "grunt-open": "~0.2.3",
    "grunt-chmod": "~1.0.3",
    "grunt-contrib-jshint": "~0.11.3",
    "grunt-contrib-uglify": "~0.10.0",
    "karma": "~0.13.15",
    "grunt-karma": "~0.12.1",
    "jasmine-core": "~2.3.4",
    "karma-jasmine": "~0.3.6",
    "phantomjs": "~1.9.18",
    "karma-phantomjs-launcher": "~0.2.1",
    "angular-mocks": "~1.2.28",
    "jquery": "~2.1.4",
    "underscore": "~1.8.3",
    "grunt-contrib-clean": "~0.6.0",
    "karma-coverage": "~0.5.3",
    "grunt-jscs": "~2.3.0",
    "grunt-contrib-concat": "~0.5.1"
  }
}

Gruntfile.js config:

module.exports = function (grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

grunt.initConfig({
    .....
    jscs: {
        src: [
            'gruntfile.js',
            '<%= sourceFolder %>/**/*.js',
            '!<%= sourceFolder %>/angular/**',
            '!<%= sourceFolder %>/es5-shim/**',
            '!<%= sourceFolder %>/**/*[.-]min.js',
            '!<%= sourceFolder %>/respond/*.js',
            '!<%= sourceFolder %>/angular-ui-bootstrap/*.js',
            '!<%= sourceFolder %>/analytics/angulartics*.js'
        ],
        options: {
            config: '.jscsrc',
            fix: true
        }
    }
});
Elatia answered 9/12, 2015 at 17:24 Comment(4)
I am guessing that jscs is installed & working on the build server?Dynah
The issue was that i was running an old version of node/npm locally and then getting the build going in that environment never worked. So, no, the build server does not and has not ever worked. Locally on ~1.X node/npm works fine.Hypogeous
Have you tried completely removing the node_modules, clearing the npm cache & a doing a fresh npm install of the project?Dynah
yes, i have ...(stupid char limits)Hypogeous
E
0

grunt-express project holds a dependency that causes this failure. grunt-express has not been released in over 2 years therefor i've chosen to move to grunt-contrib-connect and use that instead and this solved my issue! Hope it helps anyone who runs into this issue.

Elatia answered 23/3, 2016 at 23:44 Comment(0)
E
1

Just created a test project and I was able to reproduce the issue. It's in this line:

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

Use load-grunt-tasks instead:

require('load-grunt-tasks')(grunt);

Also run npm i --save-dev load-grunt-tasks and you're good to go!

Earthen answered 19/12, 2015 at 16:8 Comment(4)
This didn't seem to do the trick. I am still getting the exact same errorHypogeous
Can you do a npm prune?Earthen
That's super weird. I was able to reproduce and fix it with the steps above. I'll try again later tonight and setup a demo project.Earthen
were you able to get this reproduced again and fixed?Hypogeous
E
0

grunt-express project holds a dependency that causes this failure. grunt-express has not been released in over 2 years therefor i've chosen to move to grunt-contrib-connect and use that instead and this solved my issue! Hope it helps anyone who runs into this issue.

Elatia answered 23/3, 2016 at 23:44 Comment(0)
F
-1

Whenever I have build problems related to node.js/npm upgrades, 10/10 times it has been a faulty dependency.

Try bumping the grunt-jscs dependency to 2.5: https://www.npmjs.com/package/grunt-jscs

Frans answered 16/12, 2015 at 21:23 Comment(2)
Any difference in the error output? Try bumping as much stuff as you can - you are running a bleeding edge version of node/npm. I jumped to the 4.x series and gulp needed a ton of stuff to start working again - I'm guessing grunt is the same story.Frans
I used ncu to check for updates and all that is not up to date is angular-mocks (which is like that because i am on an old version of angular). Same errorHypogeous

© 2022 - 2024 — McMap. All rights reserved.