grunt-contrib-imagemin: Fatal error: Cannot read property 'contents' of undefined
i am getting that error after run: grunt imagemin
Running “imagemin:dist” (imagemin) task Fatal error: Cannot read property ‘contents’ of undefined
the funnest part is: i am using the same code and images from other project for test and in that projects everything works perfect. \o/ i tried use --force but keeps the same error, the task minimize one image but not all.
my gruntfile.js //Image min ===============================
var imagemin;
config.imagemin = imagemin = {};
imagemin.dist = {
options: {
optimizationLevel: 5,
progressive: true,
},
files: [{
expand: true,
cwd: 'public/images/',
src: ['**/*.{png,jpg,gif}'],
dest: 'public/images/min'
}]
};
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 93
Commits related to this issue
- fix imaginmin version for issue https://github.com/gruntjs/grunt-contrib-imagemin/issues/330 — committed to Conf4IT/devopsconf by rodgaray 9 years ago
- Merge pull request #329 from sapegin/patch-1 Update imagemin to 4.0.0 r=vladikoff — committed to gruntjs/grunt-contrib-imagemin by vladikoff 9 years ago
- Update Fixes recent imagemin bug, see https://github.com/gruntjs/grunt-contrib-imagemin/issues/330 — committed to TryKickoff/kickoff by mrmartineau 9 years ago
- Merge branch 'next' of https://github.com/TryKickoff/kickoff into next # By Zander Martineau (3) and others * 'next' of https://github.com/TryKickoff/kickoff: remove html validation grunt task ad... — committed to TryKickoff/kickoff by mrmartineau 9 years ago
- Workaround for image minification regression Added workaround fix for regression introduced into image minification build task as discussed here: https://github.com/gruntjs/grunt-contrib-imagemin/is... — committed to rgladwell/generator-simple-static-site by rgladwell 8 years ago
- Locks grunt-contrib-imagemin version This commit fixes grunt-contrib-imagemin version in order to fix build errors in newer versions of npm. This commit also adds package-lock.json to .gitignore, si... — committed to sing-group/pandrugs-frontend by lipido 6 years ago
I resolved this by bumping
grunt-contrib-imagemin
inpackage.json
to^1.0.0
, then givin’ it the ol’npm cache clean && npm install grunt-contrib-imagemin
.this fixes this issue… https://github.com/gruntjs/grunt-contrib-imagemin/pull/329 let’s see how long until it gets merged, in the meantime for those who need to deploy you can create a post install script to run the library update with
node_modules
package.json
to use"grunt-contrib-imagemin": "1.0.0"
and"vinyl-fs": "2.3.1"
npm install
That’s what did it for me.
@lashan These steps worked for me.
npm i -D imagemin vinyl-fs@2.2.1 works for me.
Adding "
vinyl-fs": "2.2.1"
as devDepenency fixed the problem for me.Same for me, everything works in an outdated version, but if I run npm install and use new updates will get this error…
I think is something related to the function used to calculate size differences between source and output files.
It works if I check for undefined data[0] in this anonymous function: node_modules/grunt-contrib-imagemin/tasks/imagemin.js:48
the “fix” since the image size difference still won’t be calculated:
the anonymous callback function to put the fix:
Guess why
data
argument is undefined whenerr
is null I think is the key to really fix this…