问题
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