grunt-contrib-imagemin output "Fatal error: ENOENT, no such file or directory"

16,653

Solution 1

Uninstalling version 0.5.0 and going back to version 0.3.0 with the following commands should restore the prior functionality:

npm uninstall grunt-contrib-imagemin

npm install --save-dev [email protected]

There is an issue, https://github.com/gruntjs/grunt-contrib-imagemin/issues/140, that is being worked on, and when it is fixed it should be safe to upgrade.

Solution 2

The following solutions works on...

  • Ubuntu Linux 13.10 x64
  • npm --version = 1.3.11
  • node --version = v0.10.21
  • grunt-contrib-imagemin = 0.5.0

This is a hack of a solution, but I found the task fails when it looks at the the target directory to see if the PNG image already exists and is optimized. The task would consistently finish when I ran it over and over, each time it would complete a few more images. And I could repeat the problem by running grunt clean, then grunt imagemin over and over.

The error I saw was:

bash Fatal error: ENOENT, no such file or directory 'build-production/path-to/some-image.png'

Solution

Copy the images to the target dir immediately before optimizing them. This way, the check passes and unoptimized images that are copied are replaced by their optimized equivalent.

task

grunt.task.run(
    'copy:imagemin',
    'imagemin'
);

copy configuration

copy: {
    imagemin: {
        files: [{
                expand: true,
                cwd: '<%= exponential.client.src %>',
                src: ['images/**/*.{png,jpg,gif}'],
                dest: '<%= exponential.client.buildProduction %>'
        }]
    }
}

imagemin configuration

imagemin: {
    buildProduction: {
        files: [{
            expand: true,
            cwd: '<%= exponential.client.src %>',
            src: ['images/**/*.{png,jpg,gif}'],
            dest: '<%= exponential.client.buildProduction %>'
        }]
    }
}

Solution 3

I was able to solve the problem by uninstalling optipngthat I had accidentally installed system wide.

Solution 4

Try to use cache: false

worked for me.

Solution 5

I had the same issue with grunt-contrib-imagemin and it was because I was running grunt with sudo.

My fix was to do a chown and a chmod on the entire structure then run grunt without sudo...

Share:
16,653

Related videos on Youtube

svassr
Author by

svassr

Updated on July 13, 2022

Comments

  • svassr
    svassr almost 2 years

    The command grunt imagemin output the following to a random file.

    Fatal error: ENOENT, no such file or directory 'app/public/assets/img/epg/recordseries.png'
    

    What's funny is that each time I run the command grunt imagemin again, it manages to process a few more files and ends by outputting the same error about another file.

    I'm using

    node v0.10.24
    npm 1.3.21
    [email protected]
    [email protected] node_modules/grunt-contrib-imagemin
    +-- [email protected]
    +-- [email protected]
    +-- [email protected] ([email protected], [email protected], [email protected])
    +-- [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
    

    Here is my grunt config for imagemin task:

    grunt.config('imagemin', {
        options: {
            optimizationLevel: 3, // 0 to 7, default =7)
            // pngquant: true
        },
        dynamic: {                                          // Multiple target
            files: [{
                expand: true,                               // Enable dynamic expansion
                cwd: '<%= context.source %>/assets/img/',   // equal to app/wesource/assets/img/
                src: ['!**/*-'+arrayToRegexStr(platformIgnoreList)+'**', '**/*.{png,jpg,jpeg,gif}'],                // Actual patterns to match //
                dest: '<%= context.public %>/assets/img/'   // equal to app/public/assets/img/
            }]
        }
    });
    
  • svassr
    svassr over 10 years
    That do the trick but I'm ending up with another error Warning: Not a JPEG file: starts with 0x89 0x50 Use --force to continue. on a particular images optimized before that one are empty.
  • Jason Aller
    Jason Aller about 10 years
    Version 0.6.0 has been released.
  • secondman
    secondman almost 10 years
    This was my issue as well. Thanks for the answer, saved me a buttload of time debugging.
  • Kirk
    Kirk over 7 years
    Same here, thanks. I needed to uninstall optipng-bin as well.