grunt-contrib-imagemin: Error: spawn ENOENT

I’m havin some troubles to build my application. When I execute imagemin task, it returns the following error:

Warning: Error: spawn /data/node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/vendor/gifsicle ENOENT in file app/assets/images/loading.gif Use --force to continue.

here is my task:

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

Any clues?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 2
  • Comments: 45 (1 by maintainers)

Most upvoted comments

try: npm uninstall grunt-contrib-imagemin npm install grunt-contrib-imagemin

When I ran my grunt build with sudo it worked!!

Ok, I was having this very same issue, was super frustrated, but after hours of research I finally figured it out.

As @pagoenka suggested in his comment, a npm permission issue prevents some grunt-contrib-imagemin dependencies to install correctly. Here’s what I did to fix it:

  1. Fix npm permissions by following their own instructions: https://docs.npmjs.com/getting-started/fixing-npm-permissions
  2. Delete project’s node_modules/ folder
  3. Restart
  4. Reinstall node modules by running npm install at the projects folder.

Hope this helps.

Cheers!

Ok… now that this PR is merged (https://github.com/gruntjs/grunt-contrib-imagemin/pull/329), i’ve tried with grunt-contrib-imagemin: 1.0.0 but I still have the issue.

I found a workaround tho.

After my npm install, if I overwrite versions of these 3 packages I have no more problems npm install jpegtran-bin@3.0.4 npm install gifsicle@3.0.1 npm install optipng-bin@3.0.1

Each one fix the issues for the matching image type (jpeg, gif, png).

My guess is : grunt-contrib-imagemin requires “imagemin”: “^4.0.0”

imagemin 4.0.0 requires : “imagemin-gifsicle”: “^4.0.0”, “imagemin-jpegtran”: “^4.0.0”, “imagemin-optipng”: “^4.0.0”,

and those latests versions of package are not working properly.

in my case, try below, works for me. node node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules/imagemin-gifsicle/node_modules/gifsicle/lib/install.js

The simple and clean fix from @aruis worked for me. +1

@aruis Save 2 hours at least for me.

@aruis: works for me

@aruis Thx!!! You saved my day!!!

try: npm uninstall grunt-contrib-imagemin npm install grunt-contrib-imagemin

actually worked for me. Thank you so much

@arius’s suggestion wasn’t quite enough - I had to clean the cache too. npm cache clean && npm uninstall grunt-contrib-imagemin && npm install grunt-contrib-imagemin

@GilmarLira +1

The npm permissions were my problem. I chose option 2 from the npm permission instructions you provided. Changed the npm default directory from /usr/local to ~/.npm-global. I didn’t want to change /usr/local/bin or /usr/local/share permissions. Then I followed the rest of your instructions and it worked! Thank you.

Hello,

I finally figured out why I was experiencing this issue.

Here is my context which is may close to yours:

  • I have a 64bytes architecture system
  • It does works properly when I runin local
  • I’ve created a docker container (which is 32bytes arch)

The same command does not work inside the container because of npm install do not overwrite library if it’s already at the right version without any architecture check.

So as @darkmavis1980 suggested, the solution is to remove the directory before each new deployment or simply add /node_modules to the .dockerignore file.

@aruis Worked!

@aruis works!

@aruis It works me,thx

+1. Exactly same issue as @dtolj