1

I am trying to compile my es6 to es5 with grunt-babel. When I enter grunt babel into the command line, it hangs and never runs babel. It doesn't return an error or crash it just hangs. I have other tasks in my Gruntfile.js and they run just fine, so the structure of the Gruntfile.js is correct.

Here is my Gruntfile:

'use strict';

module.exports = function(grunt) {
  require('load-grunt-tasks')(grunt);

  // initialize Grunt
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    'babel': {
      options: {
        sourceMap: true,
        presets: ['babel-preset-es2015']
      },
      dist: {
        files: {
          'js/survey.js': 'build/survey.js'
        }
      }
    },
    // create jshint task
    jshint: {
      dev: {
        // tell jshint what check
        src: ['Gruntfile.js', 'server.js', 'js/**/*.js', 'models/**/*.js', 'routes/**/*.js', '!build/**', '!tests/client/bundle.js', '!tests/karma_tests/bundle.js', '!js/imageMapResizer.min.js', '!js/kickstart.js', '!js/form-validator.js', '!js/imageMapResizer.js', '!js/jquery-ui.min.js', '!js/jquery.base64.js', '!js/kickstart.js'],
        options: {
          node: true,
          globals: {
            describe: true,
            it: true,
            before: true,
            after: true,
            beforeEach: true,
            afterEach: true,
            res: true
          }
        }
      },

      mocha: {
        // tell mocha where test files are
        src: ['tests/test_entry.js', '!tests/client/bundle.js', '!tests/karma_tests/bundle.js'],
        options: {
          node: true,
          globals: {
            describe: true,
            it: true,
            before: true,
            after: true,
            beforeEach: true,
            afterEach: true,
            res: true,
            expect: true
          }
        }
      },
      jasmine: {
        src: ['<%= jshint.dev.src %>', '<%= jshint.mocha.src %>'],
        options: {
          node: true,
          jasmine: true,
          globals: {
            describe: true,
            it: true,
            before: true,
            after: true,
            beforeEach: true,
            afterEach: true,
            expect: true,
            react: true
          }
        }
      },

      // create jscs task
      jscs: {
        dev: {
          // tell jscs to test the same files as jshint
          src: ['<%= jshint.dev.src %>', '<%= jshint.mocha.src %>']
        }
      }
    },

    mocha: {
      // tell mocha where the test file is
      src: ['tests/test_entry.js'],
      options: {
        node: true,
        globals: {
          describe: true,
          it: true,
          before: true,
          after: true,
          beforeEach: true,
          afterEach: true,
          res: true,
          expect: true
        }
      }
    },

    // create simplemocha task
    simplemocha: {
      dev: {
        src: ['tests/test_entry.js']
      }
    }
  });

  // register linting task
  grunt.registerTask('lint', ['jshint:dev', 'jshint:mocha', 'jshint:jasmine']);
  // register mocha test task
  grunt.registerTask('test', ['simplemocha:dev']);
  grunt.registerTask('babel', ['babel']);
  grunt.registerTask('default', ['test']);
};

Here is my package.json:

{
  "name": "event_site_bootstrap",
  "version": "0.1.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "mocha tests/test_entry.js",
    "start": "node server.js"
  },
  "author": "",
  "license": "MS-PL",
  "dependencies": {
    "bcrypt-nodejs": "latest",
    "body-parser": "^1.15.0",
    "cookie-parser": "^1.4.1",
    "dotenv": "^1.2.0",
    "eat": "^0.1.1",
    "express": "^4.13.4",
    "flash": "^1.1.0",
    "jquery": "^2.2.1",
    "multer": "^1.1.0",
    "passport": "^0.3.2",
    "passport-http": "^0.3.0",
    "sequelize": "^3.19.3",
    "sequelize-encrypted": "^0.1.0",
    "tedious": "^1.13.2"
  },
  "devDependencies": {
    "babel-cli": "^6.7.5",
    "babel-core": "^6.7.6",
    "babel-polyfill": "^6.7.4",
    "babel-preset-es2015": "^6.6.0",
    "babylon": "^6.7.0",
    "chai": "^3.2.0",
    "chai-http": "^1.0.0",
    "cli-color": "^1.1.0",
    "colors": "^1.1.2",
    "expect": "^1.9.0",
    "grunt": "^0.4.5",
    "grunt-babel": "^6.0.0",
    "grunt-cli": "^0.1.13",
    "grunt-contrib-jshint": "^0.11.3",
    "grunt-jscs": "^2.1.0",
    "grunt-mocha-cli": "^2.0.0",
    "grunt-simple-mocha": "^0.4.0",
    "load-grunt-tasks": "^3.5.0",
    "mocha": "^2.3.4"
  }
}

And .babelrc looks like this:

{
  "presets": ["es2015"]
}

I've been trying to figure this out since yesterday, but without an error message it's been difficult to know what the problem is. I am using babel as a string, but I have tried without the quotation marks too and it acted exactly the same. I have also tried adding presets: ['babel-preset-es2015'] to the options under 'babel' but it didn't change anything.

Any help would be greatly appreciated, let me know if you need more info or want to see other files. Thanks in advance for all the help!

CascadiaJS
  • 2,320
  • 2
  • 26
  • 46
  • 1
    try running `grunt babel -vvvv --stack` – Tamas Hegedus Apr 12 '16 at 18:53
  • How big is survey.js? – Tamas Hegedus Apr 12 '16 at 18:54
  • @TamasHegedus It is very small (25 lines with comments), I actually want to compile a bunch of js files from the /js folder, but it didn't work, so I tried to run it on only the survey.js file, because it was small and I could it could eliminate the possibility of the problem coming from trying to compile multiple files at the same time. – CascadiaJS Apr 12 '16 at 19:39
  • and what about running with -vvvv? Is there any output? – Tamas Hegedus Apr 12 '16 at 19:41
  • @TamasHegedus I ran `grunt babel -vvvv --stack` and it gave me a bunch of "OK"s, but then it output `Running "babel" task` repeatedly like it was running in an infinite loop. I'll edit my question with the complete stack trace, because it's too long for a comment – CascadiaJS Apr 12 '16 at 19:42
  • Also I think `'js/survey.js': 'build/survey.js'` should be `'build/survey.js': 'js/survey.js'` – Tamas Hegedus Apr 12 '16 at 19:43

1 Answers1

6

Found it! Remove the line

grunt.registerTask('babel', ['babel']);

It causes an infinite loop. You already have a task called babel, so that line just redefines it with an infinite task.

Also you might want 'js/survey.js': 'build/survey.js' to be 'build/survey.js': 'js/survey.js'. The format is target: source

Tamas Hegedus
  • 28,755
  • 12
  • 63
  • 97
  • Thanks! that fixed it. I was registering the task like a multi-task, but there is only one task to it ran babel over and over in an infinite loop – CascadiaJS Apr 12 '16 at 19:50