KnownTraveler
KnownTraveler

Reputation: 359

travis-ci build failure on grunt-contrib-imagemin task (Cannot ready property 'contents' of undefined

I am encountering an error during a travis-ci build for grunt-contrib-imagemin task...

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

The grunt build works successfully on my local machine, however it fails when executed via travis-ci

Gruntfile.js

imagemin: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg,gif}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

Local Grunt Build (output)

Running "imagemin:dist" (imagemin) task
    Minified 9 images (saved 77.32 kB)

    Done, without errors.

    Execution Time (2016-01-13 17:04:49 UTC)
    imagemin:dist  1.6s  100%
    Total 1.6s

Travis CI grunt build (output)

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


    Execution Time (2016-01-13 17:00:32 UTC)
    loading tasks    9ms   2%
    imagemin:dist  441ms  98%
    Total 450ms Use --force to continue.

        Aborted due to warnings.

I have tried to determine if there is a syntax issue in how I am declaring src in the task... however, that does not appear to be the case... as I can successfully complete the build locally without error using a few different syntax styles, including the example provided by Grunt for grunt-contrib-imagemin

Ref: https://github.com/gruntjs/grunt-contrib-imagemin

dynamic: {                         // Another target
      files: [{
        expand: true,                  // Enable dynamic expansion
        cwd: 'src/',                   // Src matches are relative to this path
        src: ['**/*.{png,jpg,gif}'],   // Actual patterns to match
        dest: 'dist/'                  // Destination path prefix
      }]

Any thoughts or suggestions?

Upvotes: 2

Views: 200

Answers (2)

crmpicco
crmpicco

Reputation: 17181

  1. Delete node_modules

  2. Change package.json to use "grunt-contrib-imagemin": "1.0.0" and "vinyl-fs": "2.3.1"

  3. Do npm install

Upvotes: 0

KnownTraveler
KnownTraveler

Reputation: 359

As a follow-up...

I have successfully moved passed this issue via a simple workaround by swapping out "grunt-contrib-imagemin": "^1.0.0" for "grunt-image": "^1.2.1" ... and subsequently updating my Gruntfile.js by replacing imagemin tasks with image tasks...

Local builds and Travis CI builds are now succeeding with the same results.

Gruntfile.js

image: {
      dist: {
        files: [{
          expand: true,
          cwd: '<%= yeoman.app %>/images',
          src: '{,*/}*.{png,jpg,jpeg,gif}',
          dest: '<%= yeoman.dist %>/images'
        }]
      }
    },

Sample build output below via local machine and via travis-ci:

Running "image:dist" (image) task
✔ app/images/npmjs.png -> before=3.75 kB after=158 B reduced=3.59 kB(95.9%)
✔ app/images/bootstrap.png -> before=41.5 kB after=21.93 kB reduced=19.57 kB(47.2%)
✔ app/images/bowerjs.png -> before=17.71 kB after=6.65 kB reduced=11.06 kB(62.5%)
✔ app/images/nodejs.png -> before=8.45 kB after=2.93 kB reduced=5.51 kB(65.3%)
✔ app/images/starterlog.png -> before=34.53 kB after=10.58 kB reduced=23.95 kB(69.3%)
✔ app/images/gruntjs.png -> before=84.38 kB after=27.98 kB reduced=56.4 kB(66.8%)
✔ app/images/firebase.png -> before=32.03 kB after=12.19 kB reduced=19.83 kB(61.9%)
✔ app/images/fontawesome.png -> before=12.01 kB after=5.63 kB reduced=6.38 kB(53.1%)
✔ app/images/angular.png -> before=41.5 kB after=18.63 kB reduced=22.87 kB(55.1%)

Done, without errors.

Execution Time (2016-01-13 17:47:44 UTC)
image:dist  2.6s  99%
Total 2.6s

This solution with grunt-image is working on my Angular + Firebase application... which I am deploying to Firebase Hosting via travis-ci and the deployment tool dpl.

However I still haven't determined the solution to the original bug/issue with grunt-contrib-imagemin in travis-ci

Any ideas would be much appreciated. Cheers!

Upvotes: 4

Related Questions