Could not find a declaration file for module 'firebase-tools'

随声附和 提交于 2021-02-18 03:17:52

问题


I am writing my first cloud function for Firebase and it requires the firebase-tools module. I've installing it by adding it to my dependencies in the package.json file and running npm install.

Then I tried to import it using import * as tools from 'firebase-tools';, but I get this error:

Could not find a declaration file for module 'firebase-tools'. 'c:/Users/LENOVO/Nouveau dossier/functions/node_modules/firebase-tools/lib/index.js' implicitly has an 'any' type. Try npm install @types/firebase-tools if it exists or add a new declaration (.d.ts) file containing `declare module 'firebase-tools';

I also tried running npm install @types/firebase-tools, but apparently it does not exist and I'm not sure what I should put in the (.d.ts) file for this module.

So I'm asking if there's another solution and if I need to create a (.d.ts) file what should I put there beside declare module 'firebase-tools.


回答1:


I have same problem, too. The problem is that firebase-tools modules don't have (.d.ts)file. I found that we have 3 solutions in this situation.

  • install @types/xxx ←you have done, but it doesn't exist.
  • self made (.d.ts)file ←I don't know very well.
  • use "require" instead of "import" ←I solved this way.The modules are imported as "any" type implicitly.

when ts-lint alert you "[tslint] require statement not part of an import statement (no-var-requires)", you can ignore it by comment "// tslint:disable-next-line:no-var-requires"

Thank you for reading.



来源:https://stackoverflow.com/questions/61443687/could-not-find-a-declaration-file-for-module-firebase-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!