执行uglify无法耿耿于怀

时间:2013-10-07 03:18:11

标签: gruntjs

我正在使用grunt并尝试uglify由concat任务生成的js文件。 Concat工作正常,但是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-concat运行grunt-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.

此时,我不知道我错过了什么。谁能帮助我?

1 个答案:

答案 0 :(得分:1)

我解决了这个问题。将nodejs降级为v0.10.20将其修复。