Grunt tasks stuck in endless loop
Asked Answered
H

1

6

Working on putting together a base Gruntfile.js for some upcoming projects. Starting in on a new computer so everything has been a fresh build. Installed Node and NPM using Homebrew, and then installed Grunt globally, as well as in my local directory.

Here is my package.json:

{
  "name": "timespent-prototype",
  "version": "0.1.0",
  "devDependencies": {
    "assemble": "0.4.37",
    "bower": "^1.4.1",
    "grunt": "^0.4.5",
    "grunt-contrib-concat": "^0.5.1",
    "grunt-contrib-sass": "^0.9.2",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-newer": "^1.1.0",
    "grunt-wiredep": "^2.0.0"
  }
}

And here is my Gruntfile.js:

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    concat: {
      vendor: {
       src: ['vendor/**/*.min.js'],
       dest: 'build/javascripts/library.js',
      }
    },

    // Takes your scss files and compiles them to css
    sass: {
      dist: {
        options: {
          style: 'expanded'
        },
        files: {
          'build/stylesheets/application.css': 'app/stylesheets/application/index.scss'
        }
      }
    },

    // Assembles your templates into HTML files
    assemble: {
      options: {
        layoutdir: 'app/views/layouts/',
        partials: ['app/views/partials/*.hbs'],
        flatten: true,
        expand: true
      },
      pages: {
        src: ['app/views/**/*.hbs','!app/views/layouts/*.hbs','!app/views/partials/*.hbs'],
        dest: 'build/'
      }
    },

    wiredep: {
      task: {
        src: ['app/views/layouts/*.hbs']
      }
    },

    // Watches for file changes, runs the default task
    watch: {
      files: ['app/**/*'],
      tasks: ['default'],
      options: {
        // Start another live reload server on port 1337
        livereload: 1337,
      }
    }

  });

  // Load the plugins
  grunt.loadNpmTasks('assemble');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-newer');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-wiredep');

  // Register the tasks
  grunt.registerTask('default', ['sass','assemble']);
  grunt.registerTask('watch', ['watch']);
  grunt.registerTask('concat', ['concat']);
  grunt.registerTask('wiredep', ['wiredep']);
};

The problem that I am seeing is that with multiple tasks, here specifically with wiredep and concat, the task gets stuck in a loop and never ends. Running grunt concat with verbose outputs like this:

Registering "grunt-contrib-concat" local Npm module tasks.
Reading /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Parsing /Users/jacksonlynch/projects/timespent-prototype/node_modules/grunt-contrib-concat/package.json...OK
Loading "concat.js" tasks...OK
+ concat

Running tasks: concat

Running "concat" task

Running "concat" task

Running "concat" task

Running "concat" task

Running "concat" task

Running "concat" task

Where Running "concat" task will continue to print until I stop it. As I am seeing this with multiple plugins and tasks this might be a problem with my installation of NPM or Grunt, but I'm having a very hard time debugging this. If anyone has run into this before, please let me know what helped!

Thanks!


Edit: in response to Alireza Ahmadi's comment, here is my file structure:

.
|
|_ app/
  |_ assets/
  |_ javascript/
  |_ stylesheets/
  |_ views/
|
|_ build/
  |_stylesheets/
  |_javascripts/
|
|_ vendor/
|_ bower.json
|_ Gruntfile.js
|_ package.json
Hackamore answered 6/6, 2015 at 21:28 Comment(2)
Why destination of some tasks starts with build and destination of the concat task starts with dist? Can you share your folder structure with at least 2 level of depth?Priscella
Thanks for the response! That was just a poor copy and paste, the destination should always be build, I corrected that and added the file structure requested.Hackamore
P
19

In the last 2 lines of your Gruntfile.js you have redeclared the concat and wiredep tasks and when grunt tries to run your code, It stuck in an endless loop because concat refers to an undefined concat task, So you should remove these lines:

grunt.registerTask('concat', ['concat']);
grunt.registerTask('wiredep', ['wiredep']);

In general, When you define a task named foobar with grunt.initConfig, It's defined and does not need to registered using registerTask and it can be accessible by grunt foobar command.

Priscella answered 6/6, 2015 at 22:10 Comment(2)
This was the answer. Thanks Alireza! I did not realize that initConfig would also register a task for it. Thanks so much!Hackamore
For me it was that I had my task named the same as the register config nameSelestina

© 2022 - 2024 — McMap. All rights reserved.