Search code examples
gruntjsbrunch

Grunt-brunch server Fatal error: spawn ENOENT


I have an error executing "grunt server" :

Running "brunch:server" (brunch) task result in Fatal error: spawn ENOENT

Here you can find my dependencies from package.json :

"dependencies": {
    "javascript-brunch": "1.7.0",
    "coffee-script-brunch": "1.7.2",
    "css-brunch": "1.7.0",
    "stylus-brunch": "1.7.0",
    "handlebars-brunch": "1.7.2",
    "uglify-js-brunch": "1.7.3",
    "clean-css-brunch": "1.7.1",
    "jsenv-brunch": "1.4.2",
    "auto-reload-brunch": "1.7.1",
    "moment": "2.4.0",
    "lodash": "2.4.0",
    "grunt": "0.4.2",
    "grunt-contrib-clean": "0.5.0",
    "grunt-contrib-copy": "0.4.1",
    "grunt-brunch": "0.0.2",
    "grunt-shell": "0.6.1",
    "grunt-contrib-htmlmin": "0.1.3",
    "grunt-line-remover": "0.0.2"
  },
  "devDependencies": {},
  "peerDependencies": {
    "grunt": "0.4.2"
  }

And here part of my gruntfile :

grunt.initConfig({

  pkg: grunt.file.readJSON('package.json'),

  brunch: {
    options: {
      env: ['<%= company %>', '<%= platform %>'],
      production: '<%= production %>'
    },

    build: {},

    watch: {
      options: {
        watch: true
      }
    }, 

    server: {
      options: {
        server: true
      }
    }
  },
});

grunt.loadNpmTasks('grunt-brunch');

grunt.loadTasks('tasks');

grunt.registerTask('server', [
  'init',
  'clean:build',
  'brunch:server'
]);

I tried many things nothing works, any ideas will be welcoming ?


Solution

  • The issue is due to the path settings in the task file: ./node_modules/grunt-brunch/tasks/brunch.coffee. As it is set now the brunch binary is not found leading to the ENOENT error. If you change the path to:

    BASE = "#{__dirname}/../../../"
    

    in line #2 of the task file, the binary is found and the plugin works.

    EDIT: The issue only happens if there is a brunch installed locally on the base dir. In this case it seems brunch is NOT installed into the npm-modules of the grunt-brunch package (where the path is pointing to)