sharp-loader icon indicating copy to clipboard operation
sharp-loader copied to clipboard

Error when trying to load file by import statement with query

Open tremby opened this issue 7 years ago • 3 comments

I'm working on a project in Gatsby and don't want to mess about with the canned webpack configuration it provides just to load a couple of images.

So I want to use this loader with an import line in the JS file alone, and configure it with query strings.

Is this possible?

So far I'm trying

import image from 'sharp-loader!./test.png?{"outputs":[{"format": "jpg"}]}'

I was hoping this would simply convert the PNG to a JPEG. Ideally I want to specify quality level and have it optimized too.

I'm getting

TypeError: Cannot read property 'context' of null
    at Object.module.exports ([...]/node_modules/sharp-loader/dist/sharp.js:232:29)

tremby avatar Jul 19 '18 22:07 tremby

Ah thanks! Let me look into this 😄 What are you expecting image to be? Just a string? Currently sharp-loader returns a fair chunk of metadata too and was mostly built for more complex use cases. I'll see what I can do though 🎉

izaakschroeder avatar Jul 19 '18 23:07 izaakschroeder

I don't mind what it returns -- the full object with metadata is great.

tremby avatar Jul 19 '18 23:07 tremby

Ok great I'll see if I can get to this on the weekend!

izaakschroeder avatar Jul 20 '18 06:07 izaakschroeder