New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Cannot read property 'contents' of undefined #208

Closed
ravitadi opened this Issue Apr 30, 2014 · 90 comments

Comments

Projects
None yet
@ravitadi

By placing src: ['*/'] for dyamic imagemin
it throws Fatal error: Cannot read property 'contents' of undefined.

I am trying to min all the images in a folder which has additional folders containing imgs inside of it.
This issue only happens if a folder exists inside of a folder.

@ravitadi ravitadi changed the title from Fatal error: Cannot read property 'contents' of undefined inside folder to Fatal error: Cannot read property 'contents' of undefined Apr 30, 2014

@matt-bailey

This comment has been minimized.

Show comment
Hide comment
@matt-bailey

matt-bailey May 2, 2014

I wonder if this is related in anyway to this issue I just posted?

In my case I'm getting the same error as you when I use --force in an effort to get it skip corrupt files, but I also have my src set as src: ["**/*.{png,jpg,gif}"].

I wonder if this is related in anyway to this issue I just posted?

In my case I'm getting the same error as you when I use --force in an effort to get it skip corrupt files, but I also have my src set as src: ["**/*.{png,jpg,gif}"].

@ravitadi

This comment has been minimized.

Show comment
Hide comment
@ravitadi

ravitadi May 4, 2014

maybe.. Were you able to find a work around?

ravitadi commented May 4, 2014

maybe.. Were you able to find a work around?

@jamesplease

This comment has been minimized.

Show comment
Hide comment
@jamesplease

jamesplease May 4, 2014

Member

@ravitadi try adding the file extensions as @matt-bailey suggested? Your glob might be passing along the folder to the minification libraries causing the error.

Member

jamesplease commented May 4, 2014

@ravitadi try adding the file extensions as @matt-bailey suggested? Your glob might be passing along the folder to the minification libraries causing the error.

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 4, 2014

Also seeing this same issue with v0.7.0 in WordPress Gruntfile.js#L354 and for now we are using v0.4.1 as the task per config below works for us.

WordPress Ticket https://core.trac.wordpress.org/ticket/27340

Warning: Command failed:  Used --force, continuing.
Fatal error: Cannot read property 'contents' of undefined
imagemin: {
    core: {
        expand: true,
        cwd: SOURCE_DIR,
        src: [
            'wp-{admin,includes}/images/**/*.{png,jpg,gif,jpeg}',
            'wp-includes/js/tinymce/skins/wordpress/images/*.{png,jpg,gif,jpeg}'
        ],
        dest: SOURCE_DIR
    }
},

ntwb commented May 4, 2014

Also seeing this same issue with v0.7.0 in WordPress Gruntfile.js#L354 and for now we are using v0.4.1 as the task per config below works for us.

WordPress Ticket https://core.trac.wordpress.org/ticket/27340

Warning: Command failed:  Used --force, continuing.
Fatal error: Cannot read property 'contents' of undefined
imagemin: {
    core: {
        expand: true,
        cwd: SOURCE_DIR,
        src: [
            'wp-{admin,includes}/images/**/*.{png,jpg,gif,jpeg}',
            'wp-includes/js/tinymce/skins/wordpress/images/*.{png,jpg,gif,jpeg}'
        ],
        dest: SOURCE_DIR
    }
},
@matt-bailey

This comment has been minimized.

Show comment
Hide comment
@matt-bailey

matt-bailey May 5, 2014

Hmmm. In my case (in this issue #211) the error was being caused by a corrupt image. Instead of just skipping the image the task was stopping with a fatal error.

To get round this I added a condition to the task, so that if it encountered an 'undefined' object it would just skip it and continue. I don't know if this is related to your problem, but my solution is here #211.

Hmmm. In my case (in this issue #211) the error was being caused by a corrupt image. Instead of just skipping the image the task was stopping with a fatal error.

To get round this I added a condition to the task, so that if it encountered an 'undefined' object it would just skip it and continue. I don't know if this is related to your problem, but my solution is here #211.

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 5, 2014

Thanks @matt-bailey, I did look at the issue you had in #211 and #155 though in this case there is no error indicating a corrupt/unreadable image such as the errors shown in those tickets.

ntwb commented May 5, 2014

Thanks @matt-bailey, I did look at the issue you had in #211 and #155 though in this case there is no error indicating a corrupt/unreadable image such as the errors shown in those tickets.

@matt-bailey

This comment has been minimized.

Show comment
Hide comment
@matt-bailey

matt-bailey May 5, 2014

I think this error can also be caused by the task trying to process directories rather than files. It might be worth checking out the fix by @kevva.

I think this error can also be caused by the task trying to process directories rather than files. It might be worth checking out the fix by @kevva.

@matt-bailey

This comment has been minimized.

Show comment
Hide comment
@matt-bailey

matt-bailey May 5, 2014

No worries, good luck trying to find the cause.

No worries, good luck trying to find the cause.

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva May 5, 2014

Member

Well, regardless of directories or not. It will just skip if no file is defined/is empty so it should work for you now.

https://github.com/kevva/imagemin/blob/master/index.js#L73

Member

kevva commented May 5, 2014

Well, regardless of directories or not. It will just skip if no file is defined/is empty so it should work for you now.

https://github.com/kevva/imagemin/blob/master/index.js#L73

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 5, 2014

I just tried grunt-contrib-imagemin v0.7.0 and manually bumped the imagemin dependency to use "imagemin": "^0.4.6", and ran npm install to install imagemin v0.4.6

grunt-contrib-imagemin@0.7.0 node_modules\grunt-contrib-imagemin
├── pretty-bytes@0.1.1
├── async@0.7.0
├── chalk@0.4.0 (has-color@0.1.7, ansi-styles@1.0.0, strip-ansi@0.1.1)
├── mkdirp@0.4.1 (minimist@0.0.8)
└── imagemin@0.4.6 (get-stdin@0.1.0, stat-mode@0.2.0, ware@0.2.1, rimraf@2.2.7, tempfile@0.1.3, nopt@2.2.1, image-type@0.1.4,
 fs-extra@0.8.1, imagemin-svgo@0.1.0, imagemin-pngquant@0.1.2, imagemin-optipng@0.1.0, imagemin-gifsicle@0.1.1, imagemin-jpeg

Running wp master* $ grunt imagemin:core --debug

Warning: Command failed:  Use --force to continue.

Aborted due to warnings.

Running wp master* $ grunt imagemin:core --verbose

Warning: Command failed:  Use --force to continue.

Aborted due to warnings.

Running wp master* $ grunt imagemin:core --force

Warning: Command failed:  Used --force, continuing.
Fatal error: Cannot read property 'contents' of undefined

ntwb commented May 5, 2014

I just tried grunt-contrib-imagemin v0.7.0 and manually bumped the imagemin dependency to use "imagemin": "^0.4.6", and ran npm install to install imagemin v0.4.6

grunt-contrib-imagemin@0.7.0 node_modules\grunt-contrib-imagemin
├── pretty-bytes@0.1.1
├── async@0.7.0
├── chalk@0.4.0 (has-color@0.1.7, ansi-styles@1.0.0, strip-ansi@0.1.1)
├── mkdirp@0.4.1 (minimist@0.0.8)
└── imagemin@0.4.6 (get-stdin@0.1.0, stat-mode@0.2.0, ware@0.2.1, rimraf@2.2.7, tempfile@0.1.3, nopt@2.2.1, image-type@0.1.4,
 fs-extra@0.8.1, imagemin-svgo@0.1.0, imagemin-pngquant@0.1.2, imagemin-optipng@0.1.0, imagemin-gifsicle@0.1.1, imagemin-jpeg

Running wp master* $ grunt imagemin:core --debug

Warning: Command failed:  Use --force to continue.

Aborted due to warnings.

Running wp master* $ grunt imagemin:core --verbose

Warning: Command failed:  Use --force to continue.

Aborted due to warnings.

Running wp master* $ grunt imagemin:core --force

Warning: Command failed:  Used --force, continuing.
Fatal error: Cannot read property 'contents' of undefined
@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva May 12, 2014

Member

Try re-installing it now. Hopefully this fixed issues with global binaries kevva/bin-wrapper@da7fe8b.

Member

kevva commented May 12, 2014

Try re-installing it now. Hopefully this fixed issues with global binaries kevva/bin-wrapper@da7fe8b.

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 14, 2014

Following the same steps as outlined above in my previous post I see no change and the same error.

looking through the package dependencies of grunt-contrib-imagemin I cannot find bin-wrapper to manually bump it's version to 0.3.4, what package is using bin-wrapper so I can bump the version and test your fixes?

ntwb commented May 14, 2014

Following the same steps as outlined above in my previous post I see no change and the same error.

looking through the package dependencies of grunt-contrib-imagemin I cannot find bin-wrapper to manually bump it's version to 0.3.4, what package is using bin-wrapper so I can bump the version and test your fixes?

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva May 14, 2014

Member

All bin-wrappers (optipng-bin, gifsicle, pngquant-bin, jpegtran-bin).

You might try npm cache clean && npm install grunt-contrib-imagemin.

Member

kevva commented May 14, 2014

All bin-wrappers (optipng-bin, gifsicle, pngquant-bin, jpegtran-bin).

You might try npm cache clean && npm install grunt-contrib-imagemin.

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 14, 2014

Thanks,

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin

and bumped bin-wrapper to 0.3.4 and receive the folling error on npm install

> jpegtran-bin@0.2.6 postinstall C:\xampp\htdocs\wporg-git\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin
> node index.js


fs.js:166
  binding.stat(pathModule._makeLong(path), cb);
          ^
TypeError: path must be a string
    at Object.fs.exists (fs.js:166:11)
    at Object.<anonymous> (C:\xampp\htdocs\wporg-git\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_module
s\imagemin-jpegtran\node_modules\jpegtran-bin\index.js:26:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

The same error bumping bin-wrapper to 0.3.4 via:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\image-min\node_modules\imagemin-gifsicle\node_modules\gifsicle

And unmet dependency errors for both these:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\image-min\node_modules\imagemin-optipng\node_modules\optipng-bin
\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\image-min\node_modules\imagemin-pngquant\node_modules\pngquant-bin

Manually bumping the odd package here and there is fine, but going down this rabbit warren appears full of various pitfalls, is there no other sane way to do this?

ntwb commented May 14, 2014

Thanks,

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin

and bumped bin-wrapper to 0.3.4 and receive the folling error on npm install

> jpegtran-bin@0.2.6 postinstall C:\xampp\htdocs\wporg-git\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin
> node index.js


fs.js:166
  binding.stat(pathModule._makeLong(path), cb);
          ^
TypeError: path must be a string
    at Object.fs.exists (fs.js:166:11)
    at Object.<anonymous> (C:\xampp\htdocs\wporg-git\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_module
s\imagemin-jpegtran\node_modules\jpegtran-bin\index.js:26:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

The same error bumping bin-wrapper to 0.3.4 via:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\image-min\node_modules\imagemin-gifsicle\node_modules\gifsicle

And unmet dependency errors for both these:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\image-min\node_modules\imagemin-optipng\node_modules\optipng-bin
\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\image-min\node_modules\imagemin-pngquant\node_modules\pngquant-bin

Manually bumping the odd package here and there is fine, but going down this rabbit warren appears full of various pitfalls, is there no other sane way to do this?

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva May 14, 2014

Member

As I said, clear your cache. Could you also check what bin.use() in jpegtran-bin\index.js produces and make sure there's a binary there.

Member

kevva commented May 14, 2014

As I said, clear your cache. Could you also check what bin.use() in jpegtran-bin\index.js produces and make sure there's a binary there.

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 14, 2014

I cleared the cache npm cache clean and the same error per my previous comment:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle
\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin

There is a binary jpegtran.exe here:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin\vendor\jpegtran.exe

I hardly know any Javascript and the following is beyond me and my skillset now 😉

Could you also check what bin.use() in jpegtran-bin\index.js produces

ntwb commented May 14, 2014

I cleared the cache npm cache clean and the same error per my previous comment:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-gifsicle\node_modules\gifsicle
\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin

There is a binary jpegtran.exe here:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin\vendor\jpegtran.exe

I hardly know any Javascript and the following is beyond me and my skillset now 😉

Could you also check what bin.use() in jpegtran-bin\index.js produces

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva May 14, 2014

Member

At the bottom of index.js in the jpegtran-bin folder there's module.exports.path = bin.use(). Could you add console.log(bin.use()) add see what output you get from it?

Member

kevva commented May 14, 2014

At the bottom of index.js in the jpegtran-bin folder there's module.exports.path = bin.use(). Could you add console.log(bin.use()) add see what output you get from it?

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 14, 2014

This really is beyond me...

I can add console.log(bin.use()) presumably this should be console.log(bin.use()); to the bottom of the index.js file here:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin\index.js

But because I cannot use npm install via

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin

to get the package to even install 'running something' to get an 'output' of something

ntwb commented May 14, 2014

This really is beyond me...

I can add console.log(bin.use()) presumably this should be console.log(bin.use()); to the bottom of the index.js file here:

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin\index.js

But because I cannot use npm install via

\wp\node_modules\grunt-contrib-imagemin\node_modules\imagemin\node_modules\imagemin-jpegtran\node_modules\jpegtran-bin

to get the package to even install 'running something' to get an 'output' of something

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva May 14, 2014

Member

It doesn't need to be at the bottom. Before fs.exists() (but after the BinWrapper stuff) works fine.

Member

kevva commented May 14, 2014

It doesn't need to be at the bottom. Before fs.exists() (but after the BinWrapper stuff) works fine.

@ntwb

This comment has been minimized.

Show comment
Hide comment
@ntwb

ntwb May 14, 2014

I really appreciate your time and help thus far but I will have to find someone else to look into this as I have no idea how to run something and generate the output you are asking for when I cannot install it 😖

ntwb commented May 14, 2014

I really appreciate your time and help thus far but I will have to find someone else to look into this as I have no idea how to run something and generate the output you are asking for when I cannot install it 😖

@nknj

This comment has been minimized.

Show comment
Hide comment
@nknj

nknj May 14, 2014

Having the same error here. Here is the output of console.log(bin.use()) placed before fs.exists() and after BinWrapper

TypeError: Object #<BinWrapper> has no method 'use'

nknj commented May 14, 2014

Having the same error here. Here is the output of console.log(bin.use()) placed before fs.exists() and after BinWrapper

TypeError: Object #<BinWrapper> has no method 'use'
@dheian

This comment has been minimized.

Show comment
Hide comment
@dheian

dheian May 18, 2014

Having the same error here when I run it on a test copy of our site.

The grunt run lists the first four files in my project root (saying they're already optimized), then tosses the Fatal error: Cannot read property 'contents' of undefined

Just a side note: am I specifiying the direcotries correctly? I want src and dest to be the same, starting in the project root. I used ',' for src and dest.

imagemin: {
dynamic: {
files: [{
expand: true,
cwd: '.',
src: ['**/*.{png,jpg,gif}'],
dest: '.'}]
}
}

Thanks.

dheian commented May 18, 2014

Having the same error here when I run it on a test copy of our site.

The grunt run lists the first four files in my project root (saying they're already optimized), then tosses the Fatal error: Cannot read property 'contents' of undefined

Just a side note: am I specifiying the direcotries correctly? I want src and dest to be the same, starting in the project root. I used ',' for src and dest.

imagemin: {
dynamic: {
files: [{
expand: true,
cwd: '.',
src: ['**/*.{png,jpg,gif}'],
dest: '.'}]
}
}

Thanks.

@gogromat

This comment has been minimized.

Show comment
Hide comment
@gogromat

gogromat May 22, 2014

For me it was the use of {} in pattern match.
I was using '**/*.jpg'
The use of grunt imagemin --verbose told me that I tried to match file with extension .jpg.map
Switching to '**/*.{jpg}' made it to work flawlessly

For me it was the use of {} in pattern match.
I was using '**/*.jpg'
The use of grunt imagemin --verbose told me that I tried to match file with extension .jpg.map
Switching to '**/*.{jpg}' made it to work flawlessly

@ravitadi

This comment has been minimized.

Show comment
Hide comment
@ravitadi

ravitadi May 22, 2014

@gogromat, I tried that and it still doesn't work. I have multiple formats so i tried */.{jpg,png} but still error.

@gogromat, I tried that and it still doesn't work. I have multiple formats so i tried */.{jpg,png} but still error.

@Eduruiz

This comment has been minimized.

Show comment
Hide comment
@Eduruiz

Eduruiz Jun 23, 2014

i find a corrupt image after search on the images directory, that is what caused the problem here.

Eduruiz commented Jun 23, 2014

i find a corrupt image after search on the images directory, that is what caused the problem here.

@stefanfisk

This comment has been minimized.

Show comment
Hide comment
@stefanfisk

stefanfisk Jul 4, 2014

This image triggers the bug for me.

rabatt-sexleksaker_0000_rabattkod-90x90

This image triggers the bug for me.

rabatt-sexleksaker_0000_rabattkod-90x90

@stefanfisk

This comment has been minimized.

Show comment
Hide comment
@stefanfisk

stefanfisk Jul 4, 2014

It works if I open and save it in Photoshop.

It works if I open and save it in Photoshop.

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva Jul 4, 2014

Member

@stefanfisk, it's because the image is corrupt. Will have a fix for this later today.

Member

kevva commented Jul 4, 2014

@stefanfisk, it's because the image is corrupt. Will have a fix for this later today.

@stdavis

This comment has been minimized.

Show comment
Hide comment
@stdavis

stdavis Jul 28, 2014

I'm getting the same error message and wondering if I have a corrupt image. @kevva: did you ever get a fix figured out?

stdavis commented Jul 28, 2014

I'm getting the same error message and wondering if I have a corrupt image. @kevva: did you ever get a fix figured out?

@kevva

This comment has been minimized.

Show comment
Hide comment
@kevva

kevva Aug 8, 2014

Member

Yes, should be fixed in imagemin/imagemin@4c81aca.

Member

kevva commented Aug 8, 2014

Yes, should be fixed in imagemin/imagemin@4c81aca.

@andycao

This comment has been minimized.

Show comment
Hide comment
@andycao

andycao Nov 10, 2015

thank you all, i encounter the same problem and solved by reinstall grunt-contrib-imagemin

andycao commented Nov 10, 2015

thank you all, i encounter the same problem and solved by reinstall grunt-contrib-imagemin

@corgrath

This comment has been minimized.

Show comment
Hide comment
@corgrath

corgrath Nov 10, 2015

I am getting this problem now with the latest version, version 3.2.2.

I have tried to remove all npm packages and reinstall without luck.

I am getting this problem now with the latest version, version 3.2.2.

I have tried to remove all npm packages and reinstall without luck.

@michal-husak

This comment has been minimized.

Show comment
Hide comment
@michal-husak

michal-husak Nov 10, 2015

@corgrath try to update to new version 1.0.0: "grunt-contrib-imagemin": "^1.0.0"
now it works for me

@corgrath try to update to new version 1.0.0: "grunt-contrib-imagemin": "^1.0.0"
now it works for me

@naoyeye

This comment has been minimized.

Show comment
Hide comment
@naoyeye

naoyeye Nov 10, 2015

npm cache clean && npm install grunt-contrib-imagemin

works for me

thanks @kevva.

naoyeye commented Nov 10, 2015

npm cache clean && npm install grunt-contrib-imagemin

works for me

thanks @kevva.

@moses-seeq

This comment has been minimized.

Show comment
Hide comment
@moses-seeq

moses-seeq Nov 10, 2015

I agree with @michal-husak. Referencing the last version, even with a ~ failed. However, when I updated my package.json to 1.0.0, it works.

I agree with @michal-husak. Referencing the last version, even with a ~ failed. However, when I updated my package.json to 1.0.0, it works.

@corgrath

This comment has been minimized.

Show comment
Hide comment
@corgrath

corgrath Nov 10, 2015

Awesome. I was previously on grunt-contrib-imagemin version 0.9.4, but had the latest imagemin 3.2.2.

Everything works, thanks guys!

Awesome. I was previously on grunt-contrib-imagemin version 0.9.4, but had the latest imagemin 3.2.2.

Everything works, thanks guys!

@landru29

This comment has been minimized.

Show comment
Hide comment
@landru29

landru29 Jan 12, 2016

Yes, vinyl-fs broke since version 2.3.0 !
I had to replace imagemin task by a simple copy to prod my project

Yes, vinyl-fs broke since version 2.3.0 !
I had to replace imagemin task by a simple copy to prod my project

@benurb

This comment has been minimized.

Show comment
Hide comment
@benurb

benurb Jan 12, 2016

You could also temporarily add this to your package.json:

"scripts": {
  "postinstall": "cd node_modules/grunt-contrib-imagemin/node_modules/imagemin && rm -rf node_modules/vinyl-fs && npm i vinyl-fs@2.2.x"
}

At least if you're using npm 2. For npm 3 you can use a partial shrinkwrap.

benurb commented Jan 12, 2016

You could also temporarily add this to your package.json:

"scripts": {
  "postinstall": "cd node_modules/grunt-contrib-imagemin/node_modules/imagemin && rm -rf node_modules/vinyl-fs && npm i vinyl-fs@2.2.x"
}

At least if you're using npm 2. For npm 3 you can use a partial shrinkwrap.

@benurb

This comment has been minimized.

Show comment
Hide comment
@benurb

benurb Jan 12, 2016

I created a PR in vinyl-fs, that should fix this problem.
gulpjs/vinyl-fs#142
Let's see how they think about it 😄

benurb commented Jan 12, 2016

I created a PR in vinyl-fs, that should fix this problem.
gulpjs/vinyl-fs#142
Let's see how they think about it 😄

@hypery2k

This comment has been minimized.

Show comment
Hide comment
@hypery2k

hypery2k Jan 12, 2016

@benurb can confirm that's working for me. Thanks

@benurb can confirm that's working for me. Thanks

@stedda

This comment has been minimized.

Show comment
Hide comment
@stedda

stedda Jan 12, 2016

In task-runner on src u don't need the {} anymore.
Please replace the src like this : src: '[*/*.{png,jpg,jpeg,gif,svg}]', and put the path and specific images.
For me that worked.

stedda commented Jan 12, 2016

In task-runner on src u don't need the {} anymore.
Please replace the src like this : src: '[*/*.{png,jpg,jpeg,gif,svg}]', and put the path and specific images.
For me that worked.

@sebastian-marinescu

This comment has been minimized.

Show comment
Hide comment
@sebastian-marinescu

sebastian-marinescu Jan 12, 2016

@benurb Thanks, this worked for me, after adapting it for Windows:

"scripts": {
    "postinstall": "cd node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules && del /F /Q vinyl-fs && cd.. && npm install vinyl-fs@2.2.x"
}

@benurb Thanks, this worked for me, after adapting it for Windows:

"scripts": {
    "postinstall": "cd node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules && del /F /Q vinyl-fs && cd.. && npm install vinyl-fs@2.2.x"
}

rochoa added a commit to CartoDB/deep-insights.js that referenced this issue Jan 12, 2016

@mmautner

This comment has been minimized.

Show comment
Hide comment

+1

@floydpink

This comment has been minimized.

Show comment
Hide comment
@floydpink

floydpink Jan 12, 2016

@benurb -

For npm 3 you can use a partial shrinkwrap.

Could you please explain how I can do 'a partial shrinkwrap' to solve this issue for npm 3?

@benurb -

For npm 3 you can use a partial shrinkwrap.

Could you please explain how I can do 'a partial shrinkwrap' to solve this issue for npm 3?

@revof11

This comment has been minimized.

Show comment
Hide comment

revof11 commented Jan 13, 2016

+1

@RemeJuan

This comment has been minimized.

Show comment
Hide comment
@RemeJuan

RemeJuan Jan 13, 2016

Upgrading to 1.0 and following @stedda's suggestion it is working for me.

Upgrading to 1.0 and following @stedda's suggestion it is working for me.

MagiCarbon added a commit to MagiCarbon/generator-angular-fullstack that referenced this issue Jan 13, 2016

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

see this link for details.

gruntjs/grunt-contrib-imagemin#208 (comment)
@alanshortis

This comment has been minimized.

Show comment
Hide comment
@alanshortis

alanshortis Jan 13, 2016

As @RemeJuan - upgrading to 1.0.0 and following @stedda 's suggestion is what finally fixed it for me.

As @RemeJuan - upgrading to 1.0.0 and following @stedda 's suggestion is what finally fixed it for me.

@gskachkov

This comment has been minimized.

Show comment
Hide comment
@gskachkov

gskachkov Jan 13, 2016

@stedda Thanks for solution!

@stedda Thanks for solution!

@stephenweaver

This comment has been minimized.

Show comment
Hide comment

@stedda Thanks!

@lpsBetty

This comment has been minimized.

Show comment
Hide comment
@lpsBetty

lpsBetty Jan 13, 2016

@stedda @stephenweaver what exactly do I have to change?

from

src: '{,*/}*.{png,jpg,jpeg,gif}',

to

src: '*/*.{png,jpg,jpeg,gif}',

?

@stedda @stephenweaver what exactly do I have to change?

from

src: '{,*/}*.{png,jpg,jpeg,gif}',

to

src: '*/*.{png,jpg,jpeg,gif}',

?

@samhax

This comment has been minimized.

Show comment
Hide comment
@samhax

samhax Jan 13, 2016

@stedda Thanks!!!

@lpsBetty you're almost there, you're missing [ ]
src: '[*/*.{png,jpg,jpeg,gif,svg}]' ,

samhax commented Jan 13, 2016

@stedda Thanks!!!

@lpsBetty you're almost there, you're missing [ ]
src: '[*/*.{png,jpg,jpeg,gif,svg}]' ,

@TanKucukhas

This comment has been minimized.

Show comment
Hide comment
@TanKucukhas

TanKucukhas Jan 13, 2016

Adding the code to package.json
"scripts": { "postinstall": "cd node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules && del /F /Q vinyl-fs && cd.. && npm install vinyl-fs@2.2.x" }
than npm install fixed the problem for me. Thanks for the solution.

Adding the code to package.json
"scripts": { "postinstall": "cd node_modules/grunt-contrib-imagemin/node_modules/imagemin/node_modules && del /F /Q vinyl-fs && cd.. && npm install vinyl-fs@2.2.x" }
than npm install fixed the problem for me. Thanks for the solution.

@altendo

This comment has been minimized.

Show comment
Hide comment
@altendo

altendo Jan 13, 2016

confirmed that adding the postinstall script mentioned by @benurb and @TanKucukhas works (manually ran the command but should work fine as a postinstall script).

altendo commented Jan 13, 2016

confirmed that adding the postinstall script mentioned by @benurb and @TanKucukhas works (manually ran the command but should work fine as a postinstall script).

@lvarayut

This comment has been minimized.

Show comment
Hide comment
@lvarayut

lvarayut Jan 13, 2016

Thanks @benurb. It worked like a charm!

Thanks @benurb. It worked like a charm!

vincentbernat added a commit to vincentbernat/dashkiosk that referenced this issue Jan 14, 2016

@lpsBetty

This comment has been minimized.

Show comment
Hide comment
@lpsBetty

lpsBetty Jan 14, 2016

@stedda @samhax hmm I really have problems getting it working!

it works locally (but NOT on the CI server) with this:

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

and when I add [] inside the src '[**/*.{png,jpg,jpeg,gif}]' it doesn't copy all images from the wd to destination directory.. but it would work on the CI

@stedda @samhax hmm I really have problems getting it working!

it works locally (but NOT on the CI server) with this:

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

and when I add [] inside the src '[**/*.{png,jpg,jpeg,gif}]' it doesn't copy all images from the wd to destination directory.. but it would work on the CI

@stedda

This comment has been minimized.

Show comment
Hide comment
@stedda

stedda Jan 14, 2016

@lpsBetty have you checked if the files are not corupted by git or repo when you upload them ? You should also check you're .gitattributes file and check the binary files. You should also add in you're file the following code if it's missing:
*.png binary *.jpg binary *.jpeg binary *.gif binary *.ico binary
.After this step delete images, add the correct versions again, push and pull from repo on server.Let me know if this might have been the problem.

stedda commented Jan 14, 2016

@lpsBetty have you checked if the files are not corupted by git or repo when you upload them ? You should also check you're .gitattributes file and check the binary files. You should also add in you're file the following code if it's missing:
*.png binary *.jpg binary *.jpeg binary *.gif binary *.ico binary
.After this step delete images, add the correct versions again, push and pull from repo on server.Let me know if this might have been the problem.

@lpsBetty

This comment has been minimized.

Show comment
Hide comment
@lpsBetty

lpsBetty Jan 14, 2016

@stedda it worked before all the time, so I don't think my files are corrupted.. I think it has something to do with the change of vinyl-fs

@stedda it worked before all the time, so I don't think my files are corrupted.. I think it has something to do with the change of vinyl-fs

@lpsBetty

This comment has been minimized.

Show comment
Hide comment
@lpsBetty

lpsBetty Jan 14, 2016

... ah sorry I found the problem.. svgmin also used {}

thanks again for the solution :)

... ah sorry I found the problem.. svgmin also used {}

thanks again for the solution :)

@korutx

This comment has been minimized.

Show comment
Hide comment
@korutx

korutx Jan 30, 2016

+1 for 1.0.0 version

korutx commented Jan 30, 2016

+1 for 1.0.0 version

@sbo0149

This comment has been minimized.

Show comment
Hide comment

sbo0149 commented Feb 2, 2016

@stedda Thanks!

@nottinhill

This comment has been minimized.

Show comment
Hide comment
@nottinhill

nottinhill Feb 8, 2016

@samhax answer worked for me for both svgmin and imgmin Grunt Tasks.

@samhax answer worked for me for both svgmin and imgmin Grunt Tasks.

@m1ch3lp3r3z

This comment has been minimized.

Show comment
Hide comment
@m1ch3lp3r3z

m1ch3lp3r3z Apr 2, 2016

+1 for 1.0.0

+1 for 1.0.0

@jivasquez

This comment has been minimized.

Show comment
Hide comment

Thanks!

@steelx

This comment has been minimized.

Show comment
Hide comment
@steelx

steelx Apr 26, 2017

solution
"grunt-contrib-imagemin": "^1.0.0",

steelx commented Apr 26, 2017

solution
"grunt-contrib-imagemin": "^1.0.0",

zuuperman added a commit to cultuurnet/uitpas-beheer-angular that referenced this issue Jun 29, 2017

pobocks pushed a commit to oscharvard/osc-root that referenced this issue Jan 9, 2018

pobocks pushed a commit to oscharvard/dash-docs that referenced this issue Mar 20, 2018

pobocks pushed a commit to oscharvard/dash-docs that referenced this issue Mar 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment