2013-12-14 193 views
1

我按照grunt site的文檔。執行sudo npm install -g grunt-cli後,我得到了這個輸出安裝grunt時出現問題

npm http GET https://registry.npmjs.org/grunt-cli 
    npm http 304 https://registry.npmjs.org/grunt-cli 
    npm http GET https://registry.npmjs.org/findup-sync 
    npm http GET https://registry.npmjs.org/nopt 
    npm http GET https://registry.npmjs.org/resolve 
    npm http 304 https://registry.npmjs.org/resolve 
    npm http 304 https://registry.npmjs.org/findup-sync 
    npm http 304 https://registry.npmjs.org/nopt 
    npm http GET https://registry.npmjs.org/abbrev 
    npm http GET https://registry.npmjs.org/glob 
    npm http GET https://registry.npmjs.org/lodash 
    npm http 304 https://registry.npmjs.org/abbrev 
    npm http 304 https://registry.npmjs.org/glob 
    npm http 304 https://registry.npmjs.org/lodash 
    npm http GET https://registry.npmjs.org/graceful-fs 
    npm http GET https://registry.npmjs.org/inherits 
    npm http GET https://registry.npmjs.org/minimatch 
    npm http 304 https://registry.npmjs.org/minimatch 
    npm http 304 https://registry.npmjs.org/inherits 
    npm http 304 https://registry.npmjs.org/graceful-fs 
    npm http GET https://registry.npmjs.org/lru-cache 
    npm http GET https://registry.npmjs.org/sigmund 
    npm http 304 https://registry.npmjs.org/sigmund 
    npm http 304 https://registry.npmjs.org/lru-cache 
    npm http GET https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz 
    npm http 200 https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz 
    /usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt 
    [email protected] /usr/local/lib/node_modules/grunt-cli 
    ├── [email protected] 
    ├── [email protected] ([email protected]) 
    └── [email protected] ([email protected], [email protected]) 

在此之後,當我做grunt我得到這個消息

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

    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 

這個我也跟着this link解決我的問題後,但我還是我得到了同樣的錯誤以上。

UPDATE

Gruntfile.js

module.exports = function() { 
     grunt.initConfig({ 
      min: { 
       dist: { 
        src: 'file-one.js', 
        dest: 'file-one.min.js' 
       } 
      } 
     }); 
    } 

的package.json文件

{ 
     "name": "grunt", 
     "version": "0.1.0", 
     "devDependencies": { 
     "grunt": "~0.1.11", 
     "grunt-contrib-jshint": "~0.6.3", 
     "grunt-contrib-nodeunit": "~0.2.0", 
     "grunt-contrib-uglify": "~0.2.2" 
     } 
    } 
+0

你有Gruntfile和package.json嗎? –

回答

7

您已經安裝grunt-cli作爲一個全球性的包,但你還需要安裝grunt本地。 grunt-cli軟件包會安裝全局命令行工具,但該命令行工具只會嘗試加載本地安裝的grunt模塊。這樣做的目的是爲了讓人們可以爲不同的項目製作多個版本的grunt,你需要將grunt本身作爲本地軟件包安裝在你正在使用的項目中。

從你的頁面鏈接到:

注意,在安裝咕嚕-CLI不安裝繁重任務運行! Grunt CLI的工作很簡單:運行已安裝在Gruntfile旁邊的Grunt版本。這允許多個版本的Grunt同時安裝在同一臺機器上。

所以你需要有grunt在你的package.json文件的本地依賴性,就像任何其他的模塊,哪來你不會在裏面列出grunt-cli

+0

我在我的項目中有package.json和Gruntfile.js文件。請看我更新的問題。 – 2619

+0

但是你真的已經安裝了'grunt',或者只是把它列在你的package.json中?嘗試運行npm install或者特別是npm install [email protected] – loganfsmyth

+0

我已經完成了npm的安裝並安裝了grunt。但現在我得到這個錯誤'警告:任務「分鐘」未找到。使用--force繼續。 因警告而中止。當我運行'grunt min'命令時。 – 2619

0

npm update爲我工作。 Grunt必須更新。