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 npm@1.2.4
3 info using node@v0.8.18
4 verbose read json /Users/Keva161/Documents/Web Dev/Webapps/Node/btask/package.json
5 verbose run-script [ 'pregrunt', 'grunt', 'postgrunt' ]
6 info pregrunt btask@0.0.1
7 info grunt btask@0.0.1
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 btask@0.0.1 Failed to exec grunt script
12 error btask@0.0.1 grunt: `node_modules/.bin/grunt`
12 error `sh "-c" "node_modules/.bin/grunt"` failed with 2
13 error Failed at the btask@0.0.1 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 ]
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 -
npm install -g grunt-clinpm install -g grunt-init"grunt": "node_modules\\.bin\\grunt" in package.json to "grunt": "grunt"grunt.registerTask('default', 'exec copy-require'); in Gruntfile.js to grunt.registerTask('default', ['exec','copy-require']);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.
arunkjn's answer will solve the problem. Though in accordance to the tutorial's intention, the author did not want to install grunt globally, which is also what I'm going for. Thanks to arunkjn, I figured that you could also:
npm install grunt-cligrunt.registerTask('default', 'exec copy-require'); in Gruntfile.js to grunt.registerTask('default', ['exec','copy-require']);And do npm run-script grunt again and it should work.
I've been using grunt and npm for a while now, and I've never used run_script. Maybe try this?
The scripts portion is usually for running on a remote server, (ie Heroku or Travis)
Remove the scripts block.
Then do
npm install -g grunt
May have to restart terminal after this.
cd myproject
npm install
grunt mytask