javascript - 咕噜 imagemin 错误 : Cannot read property 'contents' of undefined

标签 javascript gruntjs grunt-contrib-imagemin imagemin

当我尝试运行 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']);

};

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

最佳答案

只需将 gurnt-contrib-imagemin 更新到 1.0.0 或最新版本,您可能使用的旧版本可能是 0.9.x

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

相关文章:

javascript - Chrome Facebook Connect 窗口调整大小

visual-studio-code - 从 NW ABAP 系统检索 sapui5 BSP

gruntjs - 无法使用 grunt imagemin 优化文件夹内的图像

javascript - 咕噜观察和连接

javascript - 缩小所有图像 - Grunt

javascript - 如何使用 grunt-contrib-imagemin 的插件无损优化图像?

javascript - 在 cordova webview 中打开外部 URL(不在 AppBrowser 中)

javascript - 在 gulp 任务中使用 karma 获取报告

javascript - 在 Nodejs 中使用 Jasmine 测试 promise 是否被解决或拒绝

concatenation - concat 和 uglify 和 minify 之间有什么区别?