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.

Could not find a declaration file for module 'image-blob-reduce'

See original GitHub issue

I get this error when trying to use the module. Here’s my code:

const reduce = require('image-blob-reduce');

export async function reduceBlob(originalBlob) {
  await reduce
  .toBlob(originalBlob, { max: 300 })
  .then(blob => { 
    console.log(blob);
    return blob;
  });
}

Not sure how to solve this issue 😛

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
melnikovdvcommented, Feb 22, 2021

I made a bit more sophisticated module.

At first install npm install --save @types/pica to get types for reduce options.

Then add image-blob-reduce.d.ts to your project with such content:

declare module 'image-blob-reduce' {
    import { PicaResizeOptions } from "pica";
    namespace ImageBlobReduce {
        interface ImageBlobReduce {
            toBlob(file: File, options: ImageBlobReduceOptions): Promise<Blob>;
        }

        interface ImageBlobReduceStatic {
            new(options?: any): ImageBlobReduce;

            (options?: any): ImageBlobReduce;
        }

        interface ImageBlobReduceOptions extends PicaResizeOptions {
            max: number;
        }
    }
    const reduce: ImageBlobReduce.ImageBlobReduceStatic;
    export = reduce;
}

If you need other methods except toBlob() add them to ImageBlobReduce interface.

Then use it in your typescript files like this:

import reduce from "image-blob-reduce"
…
reduce().toBlob(this.file, { max: 3072 })
    .then(blob => {
        const formData = new FormData()
        formData.append('file', blob, name)
        return this.uploadImage(formData)
    })

Hey @puzrin, If it seems ok to you I can try to add @types for this library. Have never done it before, but it shouldn’t be very difficult.

1reaction
puzrincommented, Feb 22, 2021

@melnikovdv

Hey @puzrin, If it seems ok to you I can try to add @types for this library. Have never done it before, but it shouldn’t be very difficult.

If that does not depends on me, you don’t need my opinion 😃. I don’t use TS, do as you wish/need.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module 'module-name ...
Here are two other solutions. When a module is not yours - try to install types from @types : npm install -D @types/module-name....
Read more >
Could not find declaration file for module 'X' Error | bobbyhadz
The error "Could not find declaration file for module" occurs when TypeScript cannot find the type declaration for a module. To solve the...
Read more >
How to fix error TS7016: Could not find a declaration file for ...
Try `npm install @types/XYZ` if it exists or add a new declaration (.d. · declare module 'XYZ';. Lastly, you also need to add...
Read more >
[TypeScript] Could not find a declaration file for module 'node ...
When using apollo-env through apollo-server, I get the following error during TypeScript builds: ...
Read more >
Could not find a declaration file for module 'mongodb ... - Reddit
I'm using NextJS and Typescript, with mongodb version 3.7.3 If you go here: https://www.npmjs.com/package/@types/mongodb it states mongodb ...
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