serratus/quaggaJS

Could not find a declaration file for module 'quagga'.

philharmonie opened this issue ยท 22 comments

I want to add quagga to React and when I import it with import Quagga from "quagga"; I get:

Could not find a declaration file for module 'quagga'. '___path___/node_modules/quagga/lib/quagga.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/quagga` if it exists or add a new declaration (.d.ts) file containing `declare module 'quagga';`ts(7016)

npm i --save-dev @types/quagga is not possible because '@types/quagga@latest' is not in the npm registry.
``declare module 'quagga';` is not possible in vanilla JS as I know.

sounds like your typescript configuration is broken

I'm not using TypeScript

Well, whatever is giving you that error is using TypeScript, as that's a TypeScript error.

That means I can only use this if I use typescript as well?

No, you can use it without typescript, but whatever is giving you that error is using typescript. That error is not coming from either quagga or javascript.

My guess is that you're using the typescript compiler, but you're not writing typescript code, and you probably need to alter the configuration in some way to deal with that. What I don't know is specifically why it would make that error -- it should understand where the typescript .d.ts file is for quagga.

Do you have a tsconfig.json ?

I never ever used typescript. So I don't have a tsconfig.json file.

I use npx create-react-app barcode what creates a react app without typescript . Then I added Quagga with npm install quagga. I startet React with npm start.
I open the App.js, added import quagga from "quagga"; and then I have that issue.

So there is no typescript and no modification at all. The import is the only change that exists.

So what step produces the error message?

Iโ€˜m adding import quagga from "quagga"; and then there is the issue

where "there"?

In Visual Studio Code

like, in the code editor window itself? or is it after you run some step or something?

When I add the import line, there is a gray line under the โ€œquaggaโ€œ with that error message, when I hover over it.

you can ignore that, might want to tell VSC that you're using Javascript. I believe there's a dropdown in the lower right hand corner of the status bar, near the notifications box, that you can select what language you're using.

It sounds like React is configuring for TS usage even with JS code, or something like that.

I use React very much with a ton of modules. I never had such an error message. Quagga is the first module with it

I have the same error, did you manage to fix it?

i have this issue with Angular only import module any fix it?

image

i'm guessing that your tsconfig types setting is messed up somehow

I did not know this library have a new version in https://github.com/ericblade/quagga2 with quagga2 work for me thanks!

I have the same error, I use React with Typescript.
And I fixed it with the ignore tag :

// @ts-ignore
import Quagga from 'quagga';

vncius commented

I found what the problem is, but I haven't found the solution yet.

When it uses typescript it tries to fetch the quagga.d.ts types file, apparently by default it searches the quagga lib folders inside node_modules. But in this quagga project the quagga.d.ts file is in the type-definitions folder, when I copy the quagga.d.ts file there is no error. This doesn't solve the problem, and I still haven't found a way to configure the typescript to also look in this type-definitions folder in addition to the lib folder.

/node_modules/quagga/lib/quagga.d.ts -> Typescript looks in that directory
/node_modules/quagga/type-definitions/quagga.d.ts -> Directory generated after installing over the wire

the package.json specifies where the .d.ts file is, the editor should respect that

// @ts-ignore

thanks, i fixed the error.