当我尝试运行它时,Grunt imagemin引发以下错误:

Running "imagemin:dynamic" (imagemin) task
Fatal error: Cannot read property 'contents' of undefined

这是我的package.json文件:
{
  "name": "project1",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-imagemin": "^1.0.0",
    "grunt-contrib-uglify": "^0.11.0",
    "imagemin" : "4.0.0"
  }
}

这是我的Gruntfile.js
module.exports = function(grunt) {

    grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        uglify: {
          build: {
            src: 'views/js/src/main.js',
            dest: 'views/js/build/main.js'
          }
        },

        imagemin: {
          dynamic: {
            files: [{
              expand: true,
              cwd: 'views/images/src/',
              src: ['**/*.{png,jpg,gif}'],
              dest: 'views/images/build/'
            }]
          }
        }

    });

    // 3. Where we tell Grunt we plan to use this plug-in.
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-imagemin');

    // 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
    grunt.registerTask('default', ['uglify', 'imagemin']);

};

问题是imagemin的先前版本中的flagged and evidently resolved。但是,已达成共识的解决方案是将grunt-contrib-imagemin更新为1.0.0版,并将imagemin更新为4.0.0,这已经完成,但仍然无法正常工作。

最佳答案

只需将gurnt-contrib-imagemin更新为1.0.0或最新版本,您的版本可能为0.9.x

关于javascript - Grunt Imagemin错误: Cannot read property 'contents' of undefined,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34755753/

10-12 12:29