-
Notifications
You must be signed in to change notification settings - Fork 29
[TypeScript] error TS7016: Could not find a declaration file for module 'node-fetch'. #63
Comments
I was encountering this error, and I was able to use the workaround of adding the following to my package.json dependencies:
Note the version is not Not sure why it requires this peer dependency, I think this should be handled within the Also for what it's worth I think this issue might belong in the |
I don't see how this issue belongs here though, the package doesn't even have node-fetch as a dependency 🤔 |
This may need triaged somewhere. This is relative to the rest npm package.
There are the deps in the package.json I have for it in my node_modules folder. It seems it actually does have @types/node-fetch listed. Any idea why it isnt pulling that dep into my project? Edit: I deleted package lock and node_modules, ran npm install. Seems to be working fine. I'll close this and reopen if I confirm its breaking and not fixed. Edit2: Forgot I commented my offending code out. It's still an issue. |
npm doesn't install The solution is to install that dev dependency yourself...or ask the maintainers of the said package to put it under |
This is a strange error, and putting a @types packages under dependencies doesn't seem like a satisfactory solution on any level since they're strictly only required for development. Personally I would just install it as a devDep since that solves the problem, but it makes you wonder if it should've been registered as a peerDep on a lower level package somewhere. |
What about using the |
Ironically, this is an issue that node-fetch v3 solved, with the caveat it's ESM only* Usually, I've recommended using * It's ESM only, but they suggest a super simple wrapper for CJS users in their readme, so it's not a big problem |
If it is improper to add it as a regular dependency is fine although if you all ever updated node fetch then it would fall on me to keep my types package up to date. Maybe this is just a shortcoming of npm as a whole. |
I would argue it's a shortcoming of the convention of using @types packages. In general they are a net positive for the npm community because it means we can have typescript types even if the actual package (node-fetch) hasn't supplied them on its own, but in practice it means that we're inevitably gonna run into issues when making a package that uses typescript but depends on an underlying package that doesn't. It seems to rarely be an issue but it happens. |
I am getting this error when trying to use
tsc
:It seems to be the same issue as this project had:
apollographql/apollo-tooling#1686
I may be wrong but I believe this package needs to be a dependency of the rest node module.
The text was updated successfully, but these errors were encountered: