2013-03-18 68 views
71

我使用以下命令卸載了grunt。」致命錯誤:無法找到本地咕嚕聲。「當運行「grunt」命令

npm uninstall -g grunt 

然後我再次用以下命令安裝grunt。

npm install -g grunt-cli 

訪問以下鏈接: https://npmjs.org/package/grunt-html

我想使用上述咕嚕插件

但是當我運行繁重的命令,它給了我以下錯誤:

D:\nodeJS\node_modules\grunt-html>grunt 
grunt-cli: The grunt command line interface. (v0.1.6) 

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 
+3

我看不出這有什麼用jQuery。您必須在項目目錄中安裝grunt,正如文檔中所述:http://gruntjs.com/getting-started#installing-grunt-and-gruntplugins。該錯誤消息還說:*「[...]或grunt 尚未在本地安裝到您的項目中。」*。 – 2013-03-18 18:03:35

+0

我在我的項目目錄中成功安裝了grunt。現在我該如何使用該插件 – 2013-03-18 18:14:32

+1

您安裝插件並按照其項目頁面上的說明進行操作,即您鏈接到的頁面。 – 2013-03-18 18:15:12

回答

171

gruntjs.com上所有的解釋都很好。

Note that installing grunt-cli does not install the grunt task runner! The job of the grunt CLI is simple: run the version of grunt which has been installed next to a Gruntfile. This allows multiple versions of grunt to be installed on the same machine simultaneously.

因此,在項目文件夾,您需要安裝(最好)的最新咕嚕版本

npm install grunt --save-dev 

選項--save-dev將增加gruntDEV-依賴package.json。這使得重新安裝依賴關係變得容易。

+1

爲什麼downvote?我認爲我提供的答案是非常正確的。如果沒有,請解釋。 – asgoth 2013-06-07 04:45:59

+3

我沒有讓你失望,但可能是因爲你的第二行是不必要和迂腐的。 – Lee 2013-06-26 19:03:44

+3

@LeeWhitney我已經刪除了這一行,我只是表示錯誤消息提到了入門指南的鏈接,該鏈接應該是第一個尋找答案的地方。 – asgoth 2013-06-26 20:47:59

4

我認爲你必須增加grunt到你的package.json文件。見this link

+0

我成功在我的項目目錄中安裝了grunt。 現在我該如何使用那個插件 – 2013-03-18 18:14:13

+1

@mpang鏈接已經死了 – 2013-09-17 19:27:46

4

我的Windows咕嚕聲有這個問題,因爲我在64位Windows操作系統上安裝了32位版本的節點。當我專門安裝64位版本時,它開始工作。

+1

從我+1 ...我想知道爲什麼這被拒絕。這似乎是咕嚕聲失敗的完美合理原因。 – 2014-03-31 23:45:12

20

您必須安裝咕嚕在項目文件夾

  1. 創建您的package.json

    $ npm init 
    
  2. 安裝咕嚕這個項目,這將node_modules/下安裝。 --save-dev的將在你的package.json添加此模塊devDependency

    $ npm install grunt --save-dev 
    
  3. 然後創建gruntfile.js和運行

    $ grunt 
    
+2

另外,請確保正在創建node-modules文件夾。我不是因爲npm擁有'global = true'配置。我在這裏找到了解決方案:http://stackoverflow.com/a/13449393/1046584 – 2014-07-25 03:51:33

1

今天我有同樣的問題在Windows 32位,節點爲0.10.25,和grunt爲0.4.5。

我跟着dongho's answer,只需幾個額外的步驟。 這裏是我用來解決該錯誤的步驟:

1)創建的package.json

$ npm init 

2)本項目安裝的呼嚕聲,這點會在node_modules /安裝。--save-dev的將在你的package.json添加此模塊devDependency

$ npm install grunt --save-dev 

3)然後創建gruntfile.js,與樣本代碼:

module.exports = function(grunt) { 

    grunt.initConfig({ 
    jshint: { 
     files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'], 
     options: { 
     globals: { 
      jQuery: true 
     } 
     } 
    }, 
    watch: { 
     files: ['<%= jshint.files %>'], 
     tasks: ['jshint'] 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-jshint'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 

    grunt.registerTask('default', ['jshint']); 

}; 

這裏,src/**/*.jstest/**/*.js應實際JS文件的路徑使用的是在您的項目

4)運行npm install grunt-contrib-jshint --save-dev

5)RU ñnpm install grunt-contrib-watch --save-dev

6)運行$ grunt

注:當你需要普通包一樣CONCAT,醜化等,你需要通過npm install添加這些模塊,就是這個樣子,我們安裝jshint和步驟4 &觀看5