question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing sharp with memfs error: [Error: Input file is missing]

See original GitHub issue

I had trouble testing my code that implement sharp and memfs. I has codes that download image and cropping it to certain dimension. I use sharp to achieve the cropping. When it comes testing, I use jest and memfs. My test code has 2 parts:

  1. Download a image and save to mock volume/fileSystem that created with memfs.
  2. Cropping the downloaded image to certain dimension with sharp.

Part 1 worked perfectly, was able to download image to the fake volume and asserted with jest (exist in the fake volume).
But part 2 gave me error:[Error: Input file is missing].

const sizeToCrop = {
            width: 378,
            height: 538,
            left: 422,
            top: 0,
        };

sharp(`./downloadedImage.jpg`)
            .extract(sizeToCrop)
            .toFile(`./CroppedImage.jpg`)
            .then(() => {
                console.log(`resolve!`);
            })
            .catch((err: Error) => {
                console.log(err);
                return Promise.reject();
            });

// Error message: [Error: Input file is missing]

But when I test it with real volume. It worked fine.
Anyone has idea how to solve this? Thank you.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lovellcommented, Sep 6, 2021

It looks like memfs is a memory-based filesystem, so you’ll probably need to use something like the following:

const { fs } = require('memfs');
const file = fs.readFileSync('./downloadedImage.jpg');
sharp(file)...
0reactions
ogmarocommented, Mar 7, 2022

It looks like memfs is a memory-based filesystem;

This was helpful. I, however, used fs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing sharp with memfs error: [Error: Input file is missing]
My test code has 2 parts: Download a image and save to mock volume/fileSystem that created with memfs . Cropping the downloaded image...
Read more >
Testing sharp with memfs error: [Error: Input file is missing]
I had trouble testing my code that implement sharp and memfs . I has codes that download image and cropping it to certain...
Read more >
Error: Input file is missing or of an unsupported image format ...
Hello, This code for image upload and compression works in most cases but some requests fail ((Number of fails increase in load testing) ......
Read more >
Testing Sharp With Memfs Error: [Error: Input File Is ... - ADocLib
This error is caused by an unsupported file format or codec or by corrupted Windows Media One or more Windows Media Player files...
Read more >
memfs - npm
memfs. In-memory file-system with Node's fs API. Node's fs API implemented, see old API Status, missing list, missing opendir; Stores files ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found