Fatal error: Unable to find Gruntfile
I think what you're looking for is the actual command line tool grunt-init
found in the Project Scaffolding documentation.
Your current command grunt init
is looking for a Gruntfile.js
and the task init
inside it. It is obviously unable to find your Gruntfile.js
so is throwing that error.
Edit:
Your new error is because you have copied a Gruntfile.js
file over and the default
task (found near the bottom if you want to open it) will be calling those modules. Normally you will have used something like bower
to install them into your local directory.
Your default task I referred to above will look something like this:
grunt.registerTask('default', ['jshint', 'qunit', 'concat', 'uglify']);
This is basically saying: when I run grunt
at the command line, run the tasks jshint
, qunit
, concat
and uglify
in that order. These tasks will have been specified earlier on in the Gruntfile
. To understand the file more check out a sample Gruntfile.
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 Gruntfile.js
).
Edit 2:
It is important you understand what is happening. The Gruntfile.js
you have copied over looks to be calling "subgrunt" tasks. i.e. grunt
tasks in sub projects. Is this what you are wanting?
Following through your Gruntfile.js
- when you run grunt
it is calling the following order: 'jshint', 'nodeunit', 'subgrunt'
.
Ideally you want to write this yourself rather than copying it as there are some options being called by jshint
I am unfamiliar with. If you read the jshint documentation it doesn't mention the first three options.
I think you should try something like this:
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
unused: true,
boss: true,
eqnull: true,
node: true,
es5: true
}
files: {
src: ['path/to/your/*.js', 'another/path/to/your/*.js']
}
}
You should read through the documentation for each task and make sure you understand the options you are passing through.
Another hint. If you see a file reference like the following:
<%= jshint.gruntfile %>
This is a reference to a particular file/property set in the Gruntfile.js
. In this case, this came from the watch
task and points to the jshint.gruntfile
property as a file to watch.
I had this same error, and it turned out I just needed to run npm install first. Even though I had already installed npm previously, something had become corrupt w/ the installation. A quick re-install worked; All I needed were these two commands:
npm install
grunt jshint