Add types/node-fetch to dependencies rather than devDependencies
See original GitHub issueUsing 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:
- Created 2 years ago
- Comments:11 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sonologico Can we get a response here? Especially with Node v18, which has built-in fetch, the
node-fetch
dependency needs to be fixed.@types/node-fetch
moved intodependencies
in 5.1.2. Thanks for reporting this.