12

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 ]
4

3 回答 3

22

您正在谈论的教程使用 grunt 0.3。从那时起,Grunt 已经更新,如果您在package.json文件中使用 "grunt": "latest",那么默认情况下您将获得 grunt 0.4。

您可以阅读迁移指南以使事情正常进行。

为了让本教程的工作更加繁重,您可以这样做 -

  • 全局安装 grunt-clinpm install -g grunt-cli
  • 全局安装 grunt-initnpm install -g grunt-init
  • 在本地安装 grunt(如果你按照教程已经安装)
  • package.json更改 "grunt": "node_modules\\.bin\\grunt""grunt": "grunt"
  • 将根目录下的grunt.js重命名为Gruntfile.js
  • Gruntfile.js更改 grunt.registerTask('default', 'exec copy-require');grunt.registerTask('default', ['exec','copy-require']);
  • npm run-script grunt在命令行中照常运行。事情现在应该可以正常工作了。

您将获得一个带有 r.js 构建的构建目录。

如果您仍然无法通过上述步骤以某种方式使其工作,您可以在您的package.json文件中更改grunt: "latest"为并在 shell 中运行。grunt : "0.3"npm install

于 2013-02-20T09:35:42.747 回答
5

arunkjn的回答将解决问题。虽然按照教程的意图,作者并不想全局安装 grunt,这也是我想要的。感谢 arunkjn,我认为您还可以:

  • 通过在本地安装 grunt-clinpm install grunt-cli
  • 将根目录下的 grunt.js 重命名为 Gruntfile.js
  • 将 Gruntfile.js更改grunt.registerTask('default', 'exec copy-require');grunt.registerTask('default', ['exec','copy-require']);

再做npm run-script grunt一次,它应该工作。

于 2013-03-31T09:07:27.650 回答
2

我已经使用 grunt 和 npm 有一段时间了,但我从未使用过run_script. 也许试试这个?

scripts部分通常用于在远程服务器上运行(即 Heroku 或 Travis)


删除scripts块。

然后做

npm install -g grunt

在此之后可能必须重新启动终端。

cd myproject
npm install
grunt mytask
于 2013-02-04T23:25:40.703 回答