Fatal error unable to find gruntfile

grunt --version grunt-cli v0.1.8 grunt v0.4.1 $ npm -v 1.2.18 $ node -v v0.10.6 When I run grunt init to create the Gruntfile.js, I get error: $ grunt init A valid Gruntfile could not be fo...

grunt —version

grunt-cli v0.1.8
grunt v0.4.1

$ npm -v

1.2.18

$ node -v

v0.10.6

When I run 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 to find Gruntfile.

I have searched for Grunfile.js, and I get:

/home/ka/.npm/grunt-cli/0.1.8/package/Gruntfile.js
/home/ka/tmp/npm-1464/1368671910572-0.38816986070014536/package/Gruntfile.js
/usr/local/lib/node_modules/grunt/Gruntfile.js
/usr/local/lib/node_modules/grunt/node_modules/findup-sync/Gruntfile.js
/usr/local/lib/node_modules/grunt-cli/Gruntfile.js
/usr/local/lib/node_modules/grunt-cli/node_modules/findup-sync/Gruntfile.js
/ex/co/www/dev/htdocs/unittest/node_modules/grunt/node_modules/findup-sync/Gruntfile.js
/ex/co/www/dev/htdocs/unittest/node_modules/grunt/Gruntfile.js
/root/.npm/findup-sync/0.1.2/package/Gruntfile.js
/root/.npm/grunt/0.4.1/package/Gruntfile.js
/root/.npm/grunt-cli/0.1.8/package/Gruntfile.js

Can i just copy one of these grunt files, to /ex/co/www/dev/htdocs/unittest (where the Javascript / quint test are)? Or is there something else I am missing?

I am trying to run grunt on Centos 6.4. Also, why doesn’t grunt init create the Gruntfile.js?

cp /root/.npm/grunt/0.4.1/package/Gruntfile.js /ex/co/www/dev/htdocs/unittest/

I copied it AS-IS and now I get better errors:

grunt 
>> Local Npm module "grunt-contrib-jshint" not found. Is it installed?
>> Local Npm module "grunt-contrib-nodeunit" not found. Is it installed?
>> Local Npm module "grunt-contrib-watch" not found. Is it installed?
Warning: Task "jshint" not found. Use --force to continue.

Aborted due to warnings.

mode progress….

grunt 
Running "jshint:gruntfile" (jshint) task
Warning: Cannot call method 'forEach' of undefined Use --force to continue.

Aborted due to warnings.
kahmed@vm-devqa01 /ex/co/www/dev/htdocs/unittest $ grunt --force
Running "jshint:gruntfile" (jshint) task
Warning: Cannot call method 'forEach' of undefined Used --force, continuing.
Warning: Cannot call method 'forEach' of undefined Used --force, continuing.

Running "jshint:libs_n_tests" (jshint) task
Warning: Cannot call method 'forEach' of undefined Used --force, continuing.
Warning: Cannot call method 'forEach' of undefined Used --force, continuing.

Running "jshint:subgrunt" (jshint) task
Warning: Cannot call method 'forEach' of undefined Used --force, continuing.
Warning: Cannot call method 'forEach' of undefined Used --force, continuing.

Running "nodeunit:all" (nodeunit) task
Warning: Cannot call method 'map' of undefined Used --force, continuing.
Warning: Cannot call method 'map' of undefined Used --force, continuing.

Running "subgrunt:all" (subgrunt) task
Warning: Cannot read property 'length' of undefined Used --force, continuing.
Warning: Cannot read property 'length' of undefined Used --force, continuing.

Done, but with warnings.

My Gruntfile.js:

/*
 * grunt
 * http://gruntjs.com/
 *
 * Copyright (c) 2013 "Cowboy" Ben Alman
 * Licensed under the MIT license.
 * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
 */

'use strict';

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    nodeunit: {
      all: ['test/{grunt,tasks,util}/**/*.js']
    },
    jshint: {
      gruntfile: ['Gruntfile.js'],
      libs_n_tests: ['lib/**/*.js', '<%= nodeunit.all %>'],
      subgrunt: ['<%= subgrunt.all %>'],
      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
      }
    },
    watch: {
      gruntfile: {
        files: ['<%= jshint.gruntfile %>'],
        tasks: ['jshint:gruntfile']
      },
      libs_n_tests: {
        files: ['<%= jshint.libs_n_tests %>'],
        tasks: ['jshint:libs_n_tests', 'nodeunit']
      },
      subgrunt: {
        files: ['<%= subgrunt.all %>'],
        tasks: ['jshint:subgrunt', 'subgrunt']
      }
    },
    subgrunt: {
      all: ['test/gruntfile/*.js']
    },
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-nodeunit');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-qunit');

  grunt.registerTask('test', 'qunit:src');

  // "npm test" runs these tasks
  grunt.registerTask('test', ['jshint', 'nodeunit', 'subgrunt']);

  // Default task.
  grunt.registerTask('default', ['test']);

  // Run sub-grunt files, because right now, testing tasks is a pain.
  grunt.registerMultiTask('subgrunt', 'Run a sub-gruntfile.', function() {
    var path = require('path');
    grunt.util.async.forEachSeries(this.filesSrc, function(gruntfile, next) {
      grunt.util.spawn({
        grunt: true,
        args: ['--gruntfile', path.resolve(gruntfile)],
      }, function(error, result) {
        if (error) {
          grunt.log.error(result.stdout).writeln();
          next(new Error('Error running sub-gruntfile "' + gruntfile + '".'));
        } else {
          grunt.verbose.ok(result.stdout);
          next();
        }
      });
    }, this.async());
  });

};

I have been following a few tutorials to try and get started creating a theme and workflow for Magento 2, and am trying to setup so that I can compile all my LESS files locally, as outlined here.

The problem I am having is running grunt exec:mytheme from the root of my Magento installation. I just receive the following error:

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 to find Gruntfile.

I have added the neccessary code to the existing dev/tools/grunt/config/themes.js:

mytheme: {
    area: 'frontend',
    name: 'mytheme/default',
    locale: 'en_US',
    files: [
        'css/styles'
    ],
    dsl: 'less'
}

However I am still receiving the missing gruntfile error. Can anyone shed some light on this?

asked Jun 17, 2016 at 14:15

wickywills's user avatar

2

You always need a Gruntfile.js to run grunt (as far as I’m aware) so if you don’t have this file in your root directory I’m fairly certain this is the cause of your problem. I think the only purpose of themes.js is to add/remove themes for Grunt.

Do you have Gruntfile.js.sample in your root? You should have looking at the Magento2 repo. Just rename this to Gruntfile.js and try again.

answered Jun 17, 2016 at 16:47

Ben Crook's user avatar

Ben CrookBen Crook

15.5k3 gold badges51 silver badges99 bronze badges

2

I looked over the tutorial and it seems they never instruct you to install node or npm. From the source I followed here on a Ubuntu box I installed it this way.

Make sure you have npm and node installed globally on the server and is updated

sudo apt-get update
apt-get install nodejs
sudo apt-get install npm
sudo npm install -g grunt-cli

The from inside your Magento site root

npm install grunt --save-dev
npm install
npm update
npm install grunt-contrib-less

If all these are installed and updated, I have never had success with calling out just my theme with exec. When I start work in the morning I run grunt exec which will compile all the themes in the config/themes.js file. It just takes a few seconds. Them I run grunt watch and work on my styles, checking every so often to make sure that make saves are being seen by grunt and compiling without error.

Teja Bhagavan Kollepara's user avatar

answered Jun 17, 2016 at 16:19

circlesix's user avatar

circlesixcirclesix

4,2033 gold badges26 silver badges56 bronze badges

3

Error Description:

  • If we remove the old grunt first, and install a new grunt. We get this error:

D:wwwgrunt-testgrunt grunt-cli: The grunt command line interface. (v0.1.4)

Fatal error: Unable to find local grunt.

If you’re seeing this message, either a Gruntfile wasn’t found or grunt hasn’t been installed locally to your project.

Solution 1:

  • We might not have a grunt.js file in the project directory. Use grunt:init, which gives options such as jQuery, node,commonjs. Select what you want, then proceed.
 npm install -g grunt
  grunt:init  ( you will get following options ):
      jquery: A jQuery plugin
      node: A Node module
      commonjs: A CommonJS module
      gruntplugin: A Grunt plugin
      gruntfile: A Gruntfile (grunt.js)
  grunt init:jquery (if you want to create a jQuery related project.).
click below button to copy the code. By — JavaScript tutorial — team

Solution for v1.4:

 npm install -g grunt-cli
 npm init
   fill all details and it will create a package.json file.
 npm install grunt (for grunt dependencies.)
click below button to copy the code. By — JavaScript tutorial — team

Updated solution for new versions:

 npm install grunt --save-dev
click below button to copy the code. By — JavaScript tutorial — team

Solution 2:

Install Grunt in node_modules rather than globally

npm install -g grunt
click below button to copy the code. By — JavaScript tutorial — team
  • Do this instead:
npm install grunt --save-dev
click below button to copy the code. By — JavaScript tutorial — team

Solution 3:

npm install
click below button to copy the code. By — JavaScript tutorial — team
  • To install Grunt locally in ./node_modules (and everything else specified in the package.json file)

Solution 4:

  • If we already have a file package.json in the project and it contains grunt in dependency,
  "devDependencies": {
    "grunt": "~0.4.0",
click below button to copy the code. By — JavaScript tutorial — team
  • Then we can run npm install to resolve the issue.

Solution 5:

  • Newer versions of grunt actually specify that we have a file named Gruntfile.js (instead of the old grunt.js) .
  • We should have the grunt-cli tool be installed globally (this is done via npm install -g grunt-cli). This allows us to actually run grunt commands from the command line.
  • Secondly make sure we’ve installed grunt locally for the project. If we see the package.json doesn’t have something like "grunt": "0.4.5" in it then we should do npm install grunt -save in the project directory.

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

scmuser created the topic: Fatal error: Unable to find local grunt.
I am getting following error…

grunt lite
grunt-cli: The grunt command line interface. (v0.1.9)

Fatal error: Unable to find local grunt.

If you’re seeing this message, either a Gruntfile wasn’t found or grunt
hasn’t been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

gruntjs.com/getting-started

Solution

The command line tools are not included with the latest version of Grunt (0.4 at time of writing) instead you need to install them separately.

This is a good idea because it means you can have different versions of Grunt running on different projects but still use the nice concise grunt command to run them.

So first install the grunt cli tools globally:

npm install -g grunt-cli

(or possibly sudo npm install -g grunt-cli ).

You can establish that’s working by typing grunt –version

Now you can install the current version of Grunt local to your project. So from your project’s location…

npm install grunt –save-dev

The save-dev switch isn’t strictly necessary but is a good idea because it will mark grunt in its package.json devDependencies section as a development only module.

rajeshkumar replied the topic: Fatal error: Unable to find local grunt.
while running “npm install -g grunt-cli”, i got following code…

npm http GET registry.npmjs.org/grunt-cli
npm http 304 registry.npmjs.org/grunt-cli

npm ERR! Error: No compatible version found: grunt-cli
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR! at installTargetsError (/usr/share/npm/lib/cache.js:488:10)
npm ERR! at next_ (/usr/share/npm/lib/cache.js:438:17)
npm ERR! at next (/usr/share/npm/lib/cache.js:415:44)
npm ERR! at /usr/share/npm/lib/cache.js:408:5
npm ERR! at saved (/usr/share/npm/lib/utils/npm-registry-client/get.js:147:7)
npm ERR! at Object.oncomplete (/usr/lib/nodejs/graceful-fs.js:230:7)
npm ERR! You may report this log at:
npm ERR! < bugs.debian.org/npm >
npm ERR! or use
npm ERR! reportbug –attach /home/scmbuild/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.0-53-generic
npm ERR! command “node” “/usr/bin/npm” “install” “-g” “grunt-cli”
npm ERR! cwd /home/scmbuild
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message No compatible version found: grunt-cli
npm ERR! message No valid targets found.
npm ERR! message Perhaps not compatible with your version of node?
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/scmbuild/npm-debug.log
npm not ok
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Fatal error: Unable to find local grunt.
Seems like node is older version so need to user latest…
How to upgrade nodes in Ubantu
Install the dependencies:

sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core

Run the following commands:

git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

How to install grunt
Here’s what I did to fix this:

Uninstalled grunt globally:

npm uninstall -g grunt

Installed grunt-cli globally:

npm install -g grunt-cli

Then, in project root dir:

npm install

And all is good. Hope this works for anyone else running into this.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Fatal error: Unable to find local grunt.
After running latest nodes, while using folliowing commands i got following error…”npm install -g grunt-cli”

module.js:333
throw err;
^
Error: Cannot find module ‘graceful-fs’
at Function.Module._resolveFilename (module.js:331:15)
at Function.Module._load (module.js:273:25)
at Module.require (module.js:357:17)
at require (module.js:373:17)
at Object. (/usr/share/npm/lib/utils/ini.js:32:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Module.require (module.js:357:17)
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Fatal error: Unable to find local grunt.
From in stacekoverlfow..

Don’t download npm from aptitude or apt-get. Instead try:

git clone git://github.com/isaacs/npm.git
cd npm/scripts
chmod +x install.sh
sudo ./install.sh

saw it here: NPM can’t install appjs. Error: Cannot find module ‘graceful-fs’

or

sudo npm install

or

sudo apt-get remove npm
sudo apt-get install npm
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

  • Author
  • Recent Posts

Rajesh Kumar

Mentor for DevOps — DevSecOps — SRE — Cloud — Container & Micorservices at Cotocus

Join my following certification courses…
— DevOps Certified Professionals (DCP)
— Site Reliability Engineering Certified Professionals (SRECP)
— Master in DevOps Engineering (MDE)
— DevSecOps Certified Professionals (DSOCP)
URL — https://www.devopsschool.com/certification/

My Linkedin — https://www.linkedin.com/in/rajeshkumarin
My Email — contact@DevOpsSchool.com

Rajesh Kumar

  • Remove From My Forums
  • Question

  • I use a custom deployment script when I deploy my node.js applciation to Azure WebApp.

    Right after the npm install command, I want to execute a grunt command:

    grunt string-replace:version

    This fails during deployment, saying:

    remote: Fatal error: Unable to find local grunt

    That’s weird, because when I login into the kudu console and execute the exact same command, it succeeds. 

    Any ideas?

    • Edited by

      Monday, April 4, 2016 1:39 AM
      add title header Node.js

    • Edited by
      Gary Liu — MSFT
      Friday, July 1, 2016 6:20 AM
      edit title
    • Moved by
      Gary Liu — MSFT
      Friday, July 1, 2016 6:20 AM
      move thread

Answers

  • I just tried this, just adding a grunt call to a default custom script. The problem is not that grunt is not found on the path. It definitely starts running, but it’s grunt itself that complains with:

    remote: Fatal error: Unable to find local grunt.
    remote:
    remote: If you're seeing this message, either a Gruntfile wasn't found or grunt
    remote: hasn't been installed locally to your project. For more information about
    remote: installing and configuring grunt, please see the Getting Started guide:
    remote:
    remote: http://gruntjs.com/getting-started

    And in fact if I got to Kudu console and run ‘grunt’ from the D:homesiterepository folder, it displays exactly the same thing.

    So there is really nothing special about running it from a custom deployment script.

    • Proposed as answer by
      Peter Pan — MSFTMicrosoft contingent staff
      Wednesday, April 20, 2016 1:29 AM
    • Marked as answer by
      Peter Pan — MSFTMicrosoft contingent staff
      Friday, April 29, 2016 1:56 AM

I cannot get grunt to work at all on Windows 7. Following the instructions on the Grunt website (http://gruntjs.com/getting-started) I’ve run:

npm uninstall -g grunt-cli
npm uninstall grunt
npm uninstall -g grunt-init

git clone [email protected]:gruntjs/grunt-init-jquery.git c:/Users/me/.grunt-init/jquery

npm install -g grunt-cli
grunt-init jquery
npm install .

After that, running «grunt» produces the following output:

grunt-cli: The grunt command line interface. (v0.1.9)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:

http://gruntjs.com/getting-started

The output of npm list grunt is:

npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
C:UsersmeAppDataRoamingnpm
└─┬ [email protected]
  └── [email protected]

Running «npm install grunt» in the current directory gives the same error when running grunt.

Any thoughts? My understanding is that grunt-cli is meant to look for a local grunt install, but I can’t work out why it can’t find it.

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Fatal error u8glib hal h no such file or directory
  • Fatal error while generating source browse information iar
  • Fatal error wglcreatecontextattribsarb failed wolfenstein что делать
  • Fatal error wglcreatecontextattribsarb failed nvidia
  • Fatal error wglcreatecontextattribsarb failed doom 2016 как исправить

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии