{"id":2847,"date":"2014-02-24T00:41:30","date_gmt":"2014-02-24T00:41:30","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/24\/fatal-error-unable-to-find-gruntfile-collection-of-common-programming-errors\/"},"modified":"2014-02-24T00:41:30","modified_gmt":"2014-02-24T00:41:30","slug":"fatal-error-unable-to-find-gruntfile-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/02\/24\/fatal-error-unable-to-find-gruntfile-collection-of-common-programming-errors\/","title":{"rendered":"Fatal error: Unable to find Gruntfile-Collection of common programming errors"},"content":{"rendered":"<p>grunt &#8211;version<\/p>\n<pre><code>grunt-cli v0.1.8\ngrunt v0.4.1\n<\/code><\/pre>\n<p>$ npm -v<\/p>\n<pre><code>1.2.18\n<\/code><\/pre>\n<p>$ node -v<\/p>\n<pre><code>v0.10.6\n<\/code><\/pre>\n<p>and when i do grunt init, to create the Gruntfile.js i get error:<\/p>\n<pre><code>$ grunt init \nA valid Gruntfile could not be found. Please see the getting started guide for\nmore information on how to configure grunt: http:\/\/gruntjs.com\/getting-started\nFatal error: Unable to find Gruntfile.\n<\/code><\/pre>\n<p>I have searched for Grunfile.js, i get:<\/p>\n<pre><code>\/home\/ka\/.npm\/grunt-cli\/0.1.8\/package\/Gruntfile.js\n\/home\/ka\/tmp\/npm-1464\/1368671910572-0.38816986070014536\/package\/Gruntfile.js\n\/usr\/local\/lib\/node_modules\/grunt\/Gruntfile.js\n\/usr\/local\/lib\/node_modules\/grunt\/node_modules\/findup-sync\/Gruntfile.js\n\/usr\/local\/lib\/node_modules\/grunt-cli\/Gruntfile.js\n\/usr\/local\/lib\/node_modules\/grunt-cli\/node_modules\/findup-sync\/Gruntfile.js\n\/ex\/co\/www\/dev\/htdocs\/unittest\/node_modules\/grunt\/node_modules\/findup-sync\/Gruntfile.js\n\/ex\/co\/www\/dev\/htdocs\/unittest\/node_modules\/grunt\/Gruntfile.js\n\/root\/.npm\/findup-sync\/0.1.2\/package\/Gruntfile.js\n\/root\/.npm\/grunt\/0.4.1\/package\/Gruntfile.js\n\/root\/.npm\/grunt-cli\/0.1.8\/package\/Gruntfile.js\n<\/code><\/pre>\n<p>Can i just copy one of these grunt files, to \/ex\/co\/www\/dev\/htdocs\/unittest ( where the javascipt \/ quint test are ) ? or is there something else i am missing<\/p>\n<p>i am trying to run grunt on Centos 6.4<\/p>\n<p>and why does&#8217;nt grunt init creates the Gruntfile.js ?<\/p>\n<pre><code>cp \/root\/.npm\/grunt\/0.4.1\/package\/Gruntfile.js \/ex\/co\/www\/dev\/htdocs\/unittest\/\n<\/code><\/pre>\n<p>ok copied it AS-IS and now getting better errors:<\/p>\n<pre><code>grunt \n&gt;&gt; Local Npm module \"grunt-contrib-jshint\" not found. Is it installed?\n&gt;&gt; Local Npm module \"grunt-contrib-nodeunit\" not found. Is it installed?\n&gt;&gt; Local Npm module \"grunt-contrib-watch\" not found. Is it installed?\nWarning: Task \"jshint\" not found. Use --force to continue.\n\nAborted due to warnings.\n<\/code><\/pre>\n<p>mode progress&#8230;.<\/p>\n<pre><code>grunt \nRunning \"jshint:gruntfile\" (jshint) task\nWarning: Cannot call method 'forEach' of undefined Use --force to continue.\n\nAborted due to warnings.\nkahmed@vm-devqa01 \/ex\/co\/www\/dev\/htdocs\/unittest $ grunt --force\nRunning \"jshint:gruntfile\" (jshint) task\nWarning: Cannot call method 'forEach' of undefined Used --force, continuing.\nWarning: Cannot call method 'forEach' of undefined Used --force, continuing.\n\nRunning \"jshint:libs_n_tests\" (jshint) task\nWarning: Cannot call method 'forEach' of undefined Used --force, continuing.\nWarning: Cannot call method 'forEach' of undefined Used --force, continuing.\n\nRunning \"jshint:subgrunt\" (jshint) task\nWarning: Cannot call method 'forEach' of undefined Used --force, continuing.\nWarning: Cannot call method 'forEach' of undefined Used --force, continuing.\n\nRunning \"nodeunit:all\" (nodeunit) task\nWarning: Cannot call method 'map' of undefined Used --force, continuing.\nWarning: Cannot call method 'map' of undefined Used --force, continuing.\n\nRunning \"subgrunt:all\" (subgrunt) task\nWarning: Cannot read property 'length' of undefined Used --force, continuing.\nWarning: Cannot read property 'length' of undefined Used --force, continuing.\n\nDone, but with warnings.\n<\/code><\/pre>\n<p>My Gruntfile.js:<\/p>\n<pre><code>\/*\n * grunt\n * http:\/\/gruntjs.com\/\n *\n * Copyright (c) 2013 \"Cowboy\" Ben Alman\n * Licensed under the MIT license.\n * https:\/\/github.com\/gruntjs\/grunt\/blob\/master\/LICENSE-MIT\n *\/\n\n'use strict';\n\nmodule.exports = function(grunt) {\n\n  \/\/ Project configuration.\n  grunt.initConfig({\n    nodeunit: {\n      all: ['test\/{grunt,tasks,util}\/**\/*.js']\n    },\n    jshint: {\n      gruntfile: ['Gruntfile.js'],\n      libs_n_tests: ['lib\/**\/*.js', ''],\n      subgrunt: [''],\n      options: {\n        curly: true,\n        eqeqeq: true,\n        immed: true,\n        latedef: true,\n        newcap: true,\n        noarg: true,\n        sub: true,\n        undef: true,\n        unused: true,\n        boss: true,\n        eqnull: true,\n        node: true,\n        es5: true\n      }\n    },\n    watch: {\n      gruntfile: {\n        files: [''],\n        tasks: ['jshint:gruntfile']\n      },\n      libs_n_tests: {\n        files: [''],\n        tasks: ['jshint:libs_n_tests', 'nodeunit']\n      },\n      subgrunt: {\n        files: [''],\n        tasks: ['jshint:subgrunt', 'subgrunt']\n      }\n    },\n    subgrunt: {\n      all: ['test\/gruntfile\/*.js']\n    },\n  });\n\n  \/\/ These plugins provide necessary tasks.\n  grunt.loadNpmTasks('grunt-contrib-jshint');\n  grunt.loadNpmTasks('grunt-contrib-nodeunit');\n  grunt.loadNpmTasks('grunt-contrib-watch');\n  grunt.loadNpmTasks('grunt-contrib-qunit');\n\n  grunt.registerTask('test', 'qunit:src');\n\n  \/\/ \"npm test\" runs these tasks\n  grunt.registerTask('test', ['jshint', 'nodeunit', 'subgrunt']);\n\n  \/\/ Default task.\n  grunt.registerTask('default', ['test']);\n\n  \/\/ Run sub-grunt files, because right now, testing tasks is a pain.\n  grunt.registerMultiTask('subgrunt', 'Run a sub-gruntfile.', function() {\n    var path = require('path');\n    grunt.util.async.forEachSeries(this.filesSrc, function(gruntfile, next) {\n      grunt.util.spawn({\n        grunt: true,\n        args: ['--gruntfile', path.resolve(gruntfile)],\n      }, function(error, result) {\n        if (error) {\n          grunt.log.error(result.stdout).writeln();\n          next(new Error('Error running sub-gruntfile \"' + gruntfile + '\".'));\n        } else {\n          grunt.verbose.ok(result.stdout);\n          next();\n        }\n      });\n    }, this.async());\n  });\n\n};\n<\/code><\/pre>\n<ol>\n<li>\n<p>I think what you&#8217;re looking for is the actual command line tool <code>grunt-init<\/code> found in the Project Scaffolding documentation.<\/p>\n<p>Your current command <code>grunt init<\/code> is looking for a <code>Gruntfile.js<\/code> and the task <code>init<\/code> inside it. It is obviously unable to find your <code>Gruntfile.js<\/code> so is throwing that error.<\/p>\n<h3>Edit:<\/h3>\n<p>Your new error is because you have copied a <code>Gruntfile.js<\/code> file over and the <code>default<\/code> task (found near the bottom if you want to open it) will be calling those modules. Normally you will have used something like <code>bower<\/code> to install them into your local directory.<\/p>\n<p>Your default task I referred to above will look something like this:<\/p>\n<pre><code>grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);\n<\/code><\/pre>\n<p>This is basically saying: when I run <code>grunt<\/code> at the command line, run the tasks <code>jshint<\/code>, <code>qunit<\/code>, <code>concat<\/code> and <code>uglify<\/code> in that order. These tasks will have been specified earlier on in the <code>Gruntfile<\/code>. To understand the file more check out a sample Gruntfile.<\/p>\n<p>May I suggest taking a look at the Yeoman as it is a great tool to provide you with scaffolding for your apps (including a working <code>Gruntfile.js<\/code>).<\/p>\n<h3>Edit 2:<\/h3>\n<p>It is important you understand what is happening. The <code>Gruntfile.js<\/code> you have copied over looks to be calling &#8220;subgrunt&#8221; tasks. i.e. <code>grunt<\/code> tasks in sub projects. Is this what you are wanting?<\/p>\n<p>Following through your <code>Gruntfile.js<\/code> &#8211; when you run <code>grunt<\/code> it is calling the following order: <code>'jshint', 'nodeunit', 'subgrunt'<\/code>.<\/p>\n<p>Ideally you want to write this yourself rather than copying it as there are some options being called by <code>jshint<\/code> I am unfamiliar with. If you read the jshint documentation it doesn&#8217;t mention the first three options.<\/p>\n<p>I think you should try something like this:<\/p>\n<pre><code>jshint: {\n  options: {\n    curly: true,\n    eqeqeq: true,\n    immed: true,\n    latedef: true,\n    newcap: true,\n    noarg: true,\n    sub: true,\n    undef: true,\n    unused: true,\n    boss: true,\n    eqnull: true,\n    node: true,\n    es5: true\n  }\n  files: {\n    src: ['path\/to\/your\/*.js', 'another\/path\/to\/your\/*.js']\n  }\n}\n<\/code><\/pre>\n<p>You should read through the documentation for each task and make sure you understand the options you are passing through.<\/p>\n<p>Another hint. If you see a file reference like the following:<\/p>\n<pre><code> \n<\/code><\/pre>\n<p>This is a reference to a particular file\/property set in the <code>Gruntfile.js<\/code>. In this case, this came from the <code>watch<\/code> task and points to the <code>jshint.gruntfile<\/code> property as a file to watch.<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>grunt &#8211;version grunt-cli v0.1.8 grunt v0.4.1 $ npm -v 1.2.18 $ node -v v0.10.6 and when i do grunt init, to create the Gruntfile.js i get error: $ grunt init A valid Gruntfile could not be found. Please see the getting started guide for more information on how to configure grunt: http:\/\/gruntjs.com\/getting-started Fatal error: Unable [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2847","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2847"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2847\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}