Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
philharmonie opened this issue May 6, 2021 · 22 comments
Open

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

philharmonie opened this issue May 6, 2021 · 22 comments

Comments

@philharmonie
Copy link

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.

@ericblade
Copy link
Collaborator

sounds like your typescript configuration is broken

@philharmonie
Copy link
Author

I'm not using TypeScript

@ericblade
Copy link
Collaborator

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

@philharmonie
Copy link
Author

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

@ericblade
Copy link
Collaborator

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 ?

@philharmonie
Copy link
Author

philharmonie commented May 6, 2021

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.

@ericblade
Copy link
Collaborator

So what step produces the error message?

@philharmonie
Copy link
Author

I‘m adding import quagga from "quagga"; and then there is the issue

@ericblade
Copy link
Collaborator

where "there"?

@philharmonie
Copy link
Author

In Visual Studio Code

@ericblade
Copy link
Collaborator

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

@philharmonie
Copy link
Author

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

@ericblade
Copy link
Collaborator

ericblade commented May 9, 2021

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.

@philharmonie
Copy link
Author

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

@FelipeBrenner
Copy link

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

@walejandromt
Copy link

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

image

@ericblade
Copy link
Collaborator

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

@walejandromt
Copy link

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

@justinevacher
Copy link

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
Copy link

vncius commented Aug 25, 2023

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

@ericblade
Copy link
Collaborator

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

@AmgadAlakhadher
Copy link

// @ts-ignore

thanks, i fixed the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants