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.

@types/node-fetch@3.0.3 (latest) does not include an index.d.ts and "typings" is null in package.json

See original GitHub issue

Description

Using node-fetch 2.x with typescript not possible with latest @types/node-fetch@3.0.3 because package does not contain an index.d.ts and in the package.json “typings” is set to null.

Now I understand that this may be a deliberate choice as node-fetch@3.x does contain its types, however there are no instructions for consumers of 2.x on what to do. If the omission of the typings is intentional on @types/node-fetch@3.x then an additional section in the 2.x branch documentation indicating that TypeScript developers using node-fetch@2.x should specifically install @types/node-fetch@2.5.12.

Reproduction

Steps to reproduce the behavior:

  1. Create a default TypeScript environment.
  2. Run npm i node-fetch@2.5.12.
  3. Run npm i --save-dev @types/node-fetch.
  4. Put import fetch from 'node-fetch' at the top of your index.ts file.
  5. Run npx tsc.
  6. Build fails because
Could not find a declaration file for module 'node-fetch'. 'C:/Users/Foo/Bar/node_modules/node-fetch/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/node-fetch` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-fetch';`

Expected behaviour

The module builds successfully.

Suggestions

Option 1

Add the typings back to @types/node-fetch and instruct TypeScript consumers of node-fetch@3.x to not install @types/node-fetch as that is redundant.

Option 2

Add a section in the README.md of the 2.x branch for TypeScript consumers of node-fetch@2.x to install @types/node-fetch@2.5.12

Edit: Also update the typescript section of node-fetch@3.x which instructs the consumers of node-fetch to install @types/node-fetch as that doesn’t work;

For older versions please use the type definitions from DefinitelyTyped:

npm install --save-dev @types/node-fetch

software version
node-fetch 2.5.12
node 14.17.5
npm 6.14.14
Operating System Windows 10

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vasiliscsccommented, Oct 8, 2021

+1, this is really frustrating… any work being done on this?

As a work around in the short term you can have the following in your package.json.

{
  "dependencies": {
    "..."
    "node-fetch": "^2.6.5"
    "..."
  },
  "devDependencies": {
    "..."
    "@types/node-fetch": "^2.5.12"
    "..."
  }
}

This issue is more in the lines of either fixing @types/node-fetch@3.x or changing the documentation to specify that to use node-fetch@2.x in ts, @types/node-fetch@2.5.12 must be used.

1reaction
tinder-tannerbennettcommented, Oct 4, 2021

+1, this is really frustrating… any work being done on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript typings give me "index.d.ts is not a module"
I have installed the typings using npm i @types/webrtc --save-dev . Hovering over RTCPeerConnection in const peerConnection1 = new RTCPeerConnection(); display ...
Read more >
dts-bundle | Yarn - Package Manager
This module is a naïve string-based approach at generating bundles from the .d.ts declaration files generated by a TypeScript compiler.
Read more >
Unit testing TypeScript types with dtslint
d.ts TypeScript declaration files. My understanding is that dtslint was mostly created to check the typings of libraries at DefinitelyTyped. We' ...
Read more >
Configuring a .d.ts rollup - API Extractor
ts rollup generation, you simply need to set dtsRollup.enabled to true in your api-extractor.json config file. By default, the rollup file will be...
Read more >
Adding Custom Typings Files (*.d.ts) In An Angular 2 ...
ts files. But sometimes, you need to tell the TypeScript compiler to expect "ambient values" that are provided outside of the scope of...
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