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.

TS2688: Cannot find type definition file for 'howler'.

See original GitHub issue

After I npm install use-sound, my gatsby build is complaining about this line:

node_modules/use-sound/dist/types.d.ts:1:23 - error TS2688: Cannot find type definition file for 'howler'.

1 /// <reference types="howler" />
                        ~~~~~~

node_modules/use-sound/dist/types.d.ts:20:12 - error TS2304: Cannot find name 'Howl'.

20     sound: Howl | null;
              ~~~~

I think perhaps you need to move @types/howler from devDependencies to just plain old dependencies?

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
jwaltoncommented, May 28, 2020

Ok, this is actually a slightly old-fashioned way of importing a module in TypeScript:

/// <reference types="howler" />

The more modern way would be to just do:

import { Howl } from 'howler';

Which should be pretty familiar synatax, even if you don’t know TS. The problem is that a little lower down, we’re doing:

export interface ExposedData {
    sound: Howl | null;
    stop: (id?: string) => void;
    pause: (id?: string) => void;
    isPlaying: boolean;
    duration: number | null;
}

So because sound is of type Howl, any typescript user using this library would need the howler type definitions, otherwise they won’t know what properties are available on “sound”. If you are exporting a type from a library (like you are here), it would be customary to put @types/howler in your dependencies (it’s true the non-TS people don’t need it, but at least it’s not a very large dependency, since it’s just type definitions).

Since TypeScript is duck typed, we could just copy the definition of Howl from @types/howler into this file, and then we don’t need the dependency anymore. There’s two reasons that’s not a great idea; first if Howl changes, we’d need to update it, which doesn’t sound fun. 😛 Second, the Howl interface is 71 lines long - about 50% of the Howl type definitions - and longer than your whole .d.ts file.

0reactions
jwaltoncommented, May 28, 2020

Lemme look a little deeper into this. I’ll see if I can figure out a way to just remove that line. 😛

On Thu, May 28, 2020, 12:01 Joshua Comeau notifications@github.com wrote:

Sweet! Maybe I’ll just update the README to include that, since I don’t think it makes sense as a dependency for folks who don’t use TS

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joshwcomeau/use-sound/issues/20#issuecomment-635439556, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANQL67O33Q466OBECJUWGTRT2DGDANCNFSM4M3UFQZQ .

Read more comments on GitHub >

github_iconTop Results From Across the Web

ERROR TS2688: Cannot find type definition file for 'keyv'
I found that the keyv library is not in my packages json, but some other packages that are listed in package. json are...
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.ts) file containing `declare module 'XYZ';. If XYZ is a direct...
Read more >
@types/howler - npm
Installation. npm install --save @types/howler · Summary. This package contains type definitions for howler. · Details. Files were exported from ...
Read more >
What do "Cannot find type definition file for x" errors even mean?
npm i @types/x. And It solves this issue, but today I get the error: error TS2688: Cannot find type definition file for 'jsonwebtoken...
Read more >
Error TS2688: Cannot find type definition file for 'node'
If am receiving this error when running the vtex link command: Webpack for react@3.x builder finished in 464ms with errors: [at-loader] ...
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