zerodevx / svelte-img

High-performance responsive/progressive images for SvelteKit
https://zerodevx.github.io/svelte-img/
ISC License
321 stars 11 forks source link

TypeError #4

Closed DirtyHerby closed 1 year ago

DirtyHerby commented 1 year ago

Hi,

I get the error:

TypeError: src.reduce is not a function at SvelteImg.svelte:22:29 at Object.$$render (/node_modules/svelte/internal/index.mjs:1892:22)

Best, Tim

zerodevx commented 1 year ago

Need more details. Can you post your code?

DirtyHerby commented 1 year ago

Sure,

first I installed the package, I added imagetools plugin into my vite.config.js and add a component:

super cute cat
zerodevx commented 1 year ago

Can't see your attached image. But can you run

console.log(ImgDesignTop)

and see what it says?

DirtyHerby commented 1 year ago

At the moment i get a 500 error. When I comment out "import Img from...", the console shows me /src/lib/assets/images/jpg/AdobeStock_87816499_Preview.jpeg?run The path is converted correctly.

zerodevx commented 1 year ago

So I can't replicate it, but I suspect there's an issue with your image import. If you could create a minimal reproduction in https://node.new/sveltekit it'll be much easier for me to help.

zerodevx commented 1 year ago

I realised reproducing in Stackblitz wouldn't work because it can't install Sharp (the image transformation engine) dependencies.

At the moment i get a 500 error. When I comment out "import Img from...", the console shows me /src/lib/assets/images/jpg/AdobeStock_87816499_Preview.jpeg?run The path is converted correctly.

If importing the image returns just a path to that image, then that's wrong. It means imagetools is not picking up the image (and transforming it) correctly. I'll double-check on your installation, as well as your vite.config.js.

DirtyHerby commented 1 year ago

The plugin works and I get the correct output. Thank you for your help. I added the dependencies ("imagetools-core" and "vite-imagetools") to my package.json.

zerodevx commented 1 year ago

Strange - imagetools-core and vite-imagetools should automatically be installed if you install the @zerodevx/svelte-img package. Normally I wouldn't recommend adding these two yourself so that svelte-img can control the versioning. In any case, glad you got the setup working.