davidtheclark / grunt-spritesmith-hd

An adaptation of grunt-spritesmith to produce hd-ready sprites
Other
10 stars 5 forks source link

Getting error "Fatal error: Property 'log' of object #<Object> is not a function" #6

Closed ghost closed 10 years ago

ghost commented 10 years ago

Hi, each time I run the task with the hd option not specified I get this error. If hd is set to false I don't get the error.

Here's the verbose output from grunt:

Running "spriteHD" task

Running "spriteHD:mainPage" (spriteHD) task
Verifying property spriteHD.mainPage exists in config...OK
Files: Source/site/templates/img/tile/st-logo-large.png, Source/site/templates/img/tile/st-    logo-small.png
Options: engine="auto", destImg="Source/site/templates/img/sprites", destCSS="Source/site/templates/css/sass/sprites", imgUrl="/site/templates/img/sprites"
Creating temporary hd assets ...
Reading Source/site/templates/img/tile/st-logo-large.png...OK
Writing tempAssets/hd-main-assets/hd-st-logo-large.png...OK
Reading Source/site/templates/img/tile/st-logo-small.png...OK
Writing tempAssets/hd-main-assets/hd-st-logo-small.png...OK
Creating temporary ld assets ...
Fatal error: Property 'log' of object #<Object> is not a function

If I then run the task again, I get:

An existing directory is getting in the way of spritesmithHD creating a temporary LD asset directory at 'tempAssets/ld-main-assets'.
davidtheclark commented 10 years ago

I think I see a mistake in the code that caused your fatal error -- I had grunt.log(err) instead of grunt.log.error(err). I updated that on the current file https://github.com/davidtheclark/grunt-spritesmith-hd/blob/master/tasks/spritesmith-hd.js#L130 ---- Could you replace your install with this new code and try again?

If I'm right that that mistake was causing your original error, then I think your process was trying to log an error from node-gm but my typo screwed it up. So I'm curious what the error is that it was trying to log.

(That second error you got is the result of the first process aborting: it created the temporary ld assets, then it hit the error and exited, so the temporary assets never got erased and when you tried to run the process again they got in the way. ---- I've been annoyed by that error in the past and have been thinking that maybe instead of throwing it I should just erase any existing files at the temporary ld asset path, under the assumption that they will never be anything but relics from prior aborted processes, and continue on. Do you think that's a good idea?)

ghost commented 10 years ago

Hi, I updated that line and am now seeing what appears to be the actual error causing the task to abort. It is:

Error: spawn ENOENT

There's one error for each file I've got in the src directory.

Regarding cleanup of the temp files, I agree that cleaning them up regardless of whether the task completed or not makes sense.

Thanks.

davidtheclark commented 10 years ago

I pushed a new version fixing that mistake; and it should now remove the tempAssets directory when errors strike.

As to the ENOENT error: that's probably outside the scope of this project because it was an error thrown by GraphicsMagick for Node (https://github.com/aheckmann/gm) (?). Some searching around on Google and StackOverflow will show other people running into the same problem, for varying reasons such as permissions or conflicting names, and some possible solutions. (Here's one right in the node GM issues: https://github.com/aheckmann/gm/issues/241)

Please have a look at those and let me know if any of them fix your problem.

ghost commented 10 years ago

OK, I've got the new version. Thanks for that.

I've looked as well for solutions to the ENOENT error, but as I don't seem to be able to change the engine that's used by spritesmith-hd, I'm not able to narrow down the problem.

To be specific, when I specify hd: false I have no issue. When I remove that option, I get the ENOENT error, no matter what engine I specify. I can even specify a non-existing engine - e.g. engine: 'foo' and am not given an error about an invalid engine.

Is there another way that I can determine which engine is being used?

Thanks.

ghost commented 10 years ago

One more thing I just realized: if I set hd: false AND have engine: 'foo' I DO get the expected error:

Warning: Sorry, the spritesmith engine 'foo' could not be loaded. Please be sure you have installed it properly on your machine. Use --force to continue.
davidtheclark commented 10 years ago

Do you have GraphicsMagick or ImageMagick installed? Maybe that's the issue. Looks like I wrongly presumed (I don't remember why) that GraphicsMagick for Node (which this plugin relies on to resize images) stood alone, and didn't require a global install of GraphicsMagick or ImageMagick — but it does (see bottom of this page)!

I updated the Readme to admit this:

grunt-spritesmith — allows for a variety of spriting engines (check out its requirements). grunt-spritesmith-hd, though, is more restricted. It uses GraphicsMagick for Node for image processessing, and that requires that you already have either GraphicsMagick or ImageMagick installed.

So probably if you were trying to use an engine other than GraphicsMagick things just broke? Want to install GraphicsMagick and try again?

Sorry about the limitation. This little adaption of grunt-spritesmith is not as robust as the original. I would like to figure out a better way to pull this off, but just haven't had the chance (and I've been using a lot more SVGs lately in my own work).

ghost commented 10 years ago

OK, no problem. I didn't have either installed, so I just installed ImageMagick. Unfortunately, still seeing the same issue. Still, without hd: false I seem to be able to specify any value for engine without an error.

Thanks for your help trying to get this working. Being able to create retina sprites with spritesmith would help our team immensely.

davidtheclark commented 10 years ago

Dang. So you have have ImageMagick installed — Node's gm module says that's all it needs to work — but it's still throwing this error for you —

I just looked a little bit more through that module's docs and found this: http://aheckmann.github.io/gm/docs.html#imagemagick (and this https://github.com/aheckmann/gm/pull/29) — which suggests that the ImageMagick and GraphicsMagick CLIs are not in fact interchangeable dependencies, but that you have to do some special stuff to use IM instead of GM. (Thanks for persisting, @emcdanielpja: You're exposing all of my ignorance, which knows no bounds. It's always good to learn.)

So, here's my new guess as to what could fix things. You could install the GraphicsMagick CLI and see if that makes things work right away for you. As a longer term solution, this plugin should probably incorporate a test to see which one, GM or IM, is installed, and if IM is installed and not GM go through the steps outlined in the Node-gm-module docs to utilize IM.

ghost commented 10 years ago

All right, now we’re getting somewhere :) Installed GraphicsMagick and tried with hd: true and engine: ‘auto’. Got the error "Warning: Sorry, the spritesmith engine 'gm' could not be loaded. Please be sure you have installed it properly on your machine.” so switched to engine: ‘phantoms’ and it worked. So happy.

Let me know if there’s anything else you need me to test to get it to where you’d like. Happy to help, but it’s good for me to go forward with now.

Thanks again for your help.

Evan McDaniel

Director of Technology

PJA Advertising + Marketing

Cambridge • San Francisco

www.agencypja.comhttp://www.agencypja.com/

emcdaniel@agencypja.commailto:emcdaniel@agencypja.com

617.234.7368 cambridge office

617.230.7614 mobile

PJA is proud to be named a 2013 Top Midsize Agency of the Year by BtoB Magazine.

On May 8, 2014, at 10:50 AM, David Clark notifications@github.com<mailto:notifications@github.com> wrote:

Dang. So you have have ImageMagick installed — Node's gm module says that's all it needs to work — but it's still throwing this error for you —

I just looked a little bit more through that module's docs and found this: http://aheckmann.github.io/gm/docs.html#imagemagick (and this aheckmann/gm#29https://github.com/aheckmann/gm/pull/29) — which suggests that the ImageMagick and GraphicsMagick CLIs are not in fact interchangeable dependencies, but that you have to do some special stuff to use IM instead of GM. (Thanks for persisting, @emcdanielpjahttps://github.com/emcdanielpja: You're exposing all of my ignorance, which knows no bounds. It's always good to learn.)

So, here's my new guess as to what could fix things. You could install the GraphicsMagick CLI and see if that makes things work right away for you. As a longer term solution, this plugin should probably incorporate a test to see which one, GM or IM, is installed, and if IM is installed and not GM go through the steps outlined in the Node-gm-module docs to utilize IM.

— Reply to this email directly or view it on GitHubhttps://github.com/davidtheclark/grunt-spritesmith-hd/issues/6#issuecomment-42559030.

davidtheclark commented 10 years ago

Great! I'm going to close this issue and open up a couple of new ones to address the specific problems that we found.