1

我正在使用 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我从文档中复制了这个并删除了我不需要的任务。

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.

在这一点上,我不知道我错过了什么。谁能帮帮我?

4

1 回答 1

1

我解决了这个问题。降级 nodejs 以v0.10.20修复它。

于 2013-10-12T06:26:41.910 回答