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.

Add types/node-fetch to dependencies rather than devDependencies

See original GitHub issue

Using this library in a typescript project causes the following error on compile:

Could not find a declaration file for module 'node-fetch'. '/app/node_modules/node-fetch/lib/index.js' implicitly has an 'any' type.

This is caused by @types/node-fetch being a devDependency rather than a dependency and thus not being installed when consuming it as an npm package. Installing this @types/node-fetch module manually resolves the issue but is a messy workaround.

The Typescript handbook advises to add dependent @types to dependencies to mitigate this problem. It is also commonly done in other typescript libs that do not bundle their output, see e.g. got.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
isaachinmancommented, Dec 6, 2022

@sonologico Can we get a response here? Especially with Node v18, which has built-in fetch, the node-fetch dependency needs to be fixed.

0reactions
sonologicocommented, Dec 9, 2022

@types/node-fetch moved into dependencies in 5.1.2. Thanks for reporting this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@types/node-fetch - npm
Summary. This package contains type definitions for node-fetch (https://github.com/bitinn/node-fetch). Details.
Read more >
It is ok to have a @types library as normal dependency in ...
It is right to declare @types/node-fetch as a normal dependency if your public API depends on declarations from @types/node-fetch .
Read more >
types/node-fetch@3.0.3 (latest) does not include an index.d.ts ...
Expected behaviour. The module builds successfully. Suggestions. Option 1. Add the typings back to @types/node-fetch and instruct TypeScript ...
Read more >
@types/node-fetch | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
What are the different types of dependencies in Node.js
Create Package json file: Run the following command from the root directory of the project to create the package. · Note: · Adding...
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