Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Grunt fail?

I'm getting a weird error after running npm run-script grunt in which it tell's me that node_modules/.bin/grunt fails.

I'm following a tutorial as im pretty new to Backbone (http://dailyjs.com/2012/11/29/backbone-tutorial-1/),

Here's my package.json file.

{
  "name": "btask"
, "version": "0.0.1"
, "private": true
, "dependencies": {
    "requirejs": "latest"
  , "connect": "2.7.0"
  }
, "devDependencies": {
    "mocha": "latest"
  , "chai": "latest"
  , "grunt": "latest"
  , "grunt-exec": "latest"
  }
, "scripts": {
    "grunt": "node_modules/.bin/grunt"
  }
}

And here's a full transcript of the error.

0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli   '/Users/Keva161/.nvm/v0.8.18/bin/npm',
1 verbose cli   'run-script',
1 verbose cli   'grunt' ]
2 info using [email protected]
3 info using [email protected]
4 verbose read json /Users/Keva161/Documents/Web Dev/Webapps/Node/btask/package.json
5 verbose run-script [ 'pregrunt', 'grunt', 'postgrunt' ]
6 info pregrunt [email protected]
7 info grunt [email protected]
8 verbose unsafe-perm in lifecycle true
9 silly exec sh "-c" "node_modules/.bin/grunt"
10 silly sh,-c,node_modules/.bin/grunt,/Users/Keva161/Documents/Web Dev/Webapps/Node/btask spawning
11 info [email protected] Failed to exec grunt script
12 error [email protected] grunt: `node_modules/.bin/grunt`
12 error `sh "-c" "node_modules/.bin/grunt"` failed with 2
13 error Failed at the [email protected] grunt script.
13 error This is most likely a problem with the btask package,
13 error not with npm itself.
13 error Tell the author that this fails on your system:
13 error     node_modules/.bin/grunt
13 error You can get their info via:
13 error     npm owner ls btask
13 error There is likely additional logging output above.
14 error System Darwin 12.2.1
15 error command "node" "/Users/Keva161/.nvm/v0.8.18/bin/npm" "run-script" "grunt"
16 error cwd /Users/Keva161/Documents/Web Dev/Webapps/Node/btask
17 error node -v v0.8.18
18 error npm -v 1.2.4
19 error code ELIFECYCLE
20 verbose exit [ 1, true ]
like image 703
Keva161 Avatar asked Feb 04 '13 21:02

Keva161


People also ask

Is Grunt deprecated?

grunt. util. _ is deprecated and we highly encourage you to npm install lodash and var _ = require('lodash') to use lodash .

Is Grunt a task runner?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node.

Why do we use Grunt?

Why Use Grunt? Grunt can perform repetitive tasks very easily, such as compilation, unit testing, minifying files, running tests, etc. Grunt includes built-in tasks that extend the functionality of your plugins and scripts. The ecosystem of Grunt is huge; you can automate anything with very less effort.


1 Answers

The tutorial that you are talking about uses grunt 0.3. Grunt has updated since then and if you use "grunt": "latest" in your package.json file then you will get grunt 0.4 by default.

You can go through the migration guide to get things working.

In order to just get grunt working for the tutorial you can do this -

  • Install grunt-cli globally npm install -g grunt-cli
  • Install grunt-init globally npm install -g grunt-init
  • Install grunt locally (already installed if you followed the tutorial)
  • Change "grunt": "node_modules\\.bin\\grunt" in package.json to "grunt": "grunt"
  • Rename grunt.js in root directory to Gruntfile.js
  • Change grunt.registerTask('default', 'exec copy-require'); in Gruntfile.js to grunt.registerTask('default', ['exec','copy-require']);
  • Run npm run-script grunt as usual in command-line. Things should work fine now.

You will get a build directory with r.js build.

If you still cannot get it working somehow with the above steps, you can change grunt: "latest" to grunt : "0.3" in your package.json file and run npm install in shell.

like image 169
arunkjn Avatar answered Sep 30 '22 19:09

arunkjn