Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 735
Yasmine Avatar asked Apr 26 '20 15:04

Yasmine


2 Answers

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.

like image 189
kentaro waki Avatar answered Oct 07 '22 18:10

kentaro waki


The way I solved this problem was:

First of all, add "firebase-tools": "^9.10.0" to your package.json under /functions directory, like so:

"dependencies": {
...
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.13.1",
"firebase-tools": "^9.10.0"
},

Then, in your function code use require instead of import, like so:

const firebase_tools = require('firebase-tools');

like image 34
CloudWindMoonSun Avatar answered Oct 07 '22 18:10

CloudWindMoonSun