2013-10-07 61 views
1

我正在使用grunt並嘗試uglify由concat任務生成的js文件。 Concat工作正常,但uglify失敗並出現以下錯誤。不能得到grunt來執行uglify

Running "uglify:dist" (uglify) task 
>> Uglifying source "dist/myapp.js" failed. 
Warning: Uglification failed. Used --force, continuing. 
Warning: Cannot read property 'min' of undefined Used --force, continuing. 

node --version輸出v.0.11.8-pre

grunt --version輸出grunt-cli v0.1.9 grunt v.0.4.1

這是我Gruntfile.js。我從documentation複製了這個,並刪除了我不需要的任務。

module.exports = function(grunt) { 

    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    concat: { 
     options: { 
     separator: ';' 
     }, 
     dist: { 
     src: ['src/**/*.js'], 
     dest: 'dist/<%= pkg.name %>.js' 
     } 
    }, 
    uglify: { 
     options: { 
     banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n' 
     }, 
     dist: { 
     files: { 
      'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>'] 
     } 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-concat'); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 

    grunt.registerTask('default', ['concat', 'uglify']); 

}; 

我也跑sudo npm install XXX --save-devgruntgrunt-contrib-concatgrunt-contrib-uglify在項目目錄。我的項目目錄看起來像這樣。

. 
├─── src 
| └─── // a bunch of files/dirs here 
├─── dist 
├─── node_modules 
├─── .git 
├─── package.json 
└─── Gruntfile.js 

以下是運行grunt --verbose --stack --debug

Running "uglify:dist" (uglify) task 
[D] Task source: /home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt-contrib-uglify/tasks/uglify.js 
Verifying property uglify.dist exists in config...OK 
Files: dist/myapp.js -> dist/myapp.min.js 
Minifying with UglifyJS...>> Uglifying source "dist/myapp.js" failed. 
Warning: Uglification failed. Use --force to continue. 
TypeError: Object #<Object> has no method 'OutputStream' 
    at Object.exports.minify (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt-contrib-uglify/tasks/lib/uglify.js:30:27) 
    at /home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt-contrib-uglify/tasks/uglify.js:85:25 
    at Array.forEach (native) 
    at Object.<anonymous> (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt-contrib-uglify/tasks/uglify.js:36:16) 
    at Object.<anonymous> (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt/lib/grunt/task.js:258:15) 
    at Object.thisTask.fn (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt/lib/grunt/task.js:78:16) 
    at Object.<anonymous> (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt/lib/util/task.js:282:30) 
    at Task.runTaskFn (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt/lib/util/task.js:235:24) 
    at Task.<anonymous> (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt/lib/util/task.js:281:12) 
    at Task.<anonymous> (/home/cookiemon/Dropbox/Projects/myapp/node_modules/grunt/lib/util/task.js:215:7) 

Aborted due to warnings. 

此時輸出,我不知道我錯過了。任何人都可以幫我嗎?

+0

運行帶有詳細標誌('--verbose')的任務時輸出是什麼? – steveax

+0

@steveax我將輸出添加到我的問題。 – CookieMonster

回答

1

我解決了這個問題。將nodejs降級到v0.10.20可以修復它。