EDIT:
for others with the same problem - using const Logging: any = require('@google-cloud/logging') together with var logger = Logging() in the body of the class worked like a charm!
Remember to use var logger = Logging() to instantiate the logger library. Otherwise you will still get the logger.log is not a function!
Original post
I've got a firebase functions project, written in typescript - transpiled with webpack. I'm currently trying to implement the @google-cloud/logging library, but I'm having issues. It comes out saying
Could not find a declaration file for module "google-cloud/logging". Try
npm install @types/@google-cloud/loggingif it exists or add a new declaration (.d.ts) file containingdeclare module '@google-cloud/logging';
I've tried adding the library the following ways:
import * as Logging from '@google-cloud/logging';
import * as logging from '@google-cloud/logging';
import { Logging } from '@google-cloud/logging';
But I'm still getting this error. Trying to run a function which is using "logging" results in
logging.log is not a function
I have even tried the javascript way of requiring the library, still with no success.
My tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./",
"noImplicitAny": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
I've read that some people had success by adding a "d.ts" file to the project manually, though I did not understand much of it. Here is the link to the article in stack overflow - Importing non-typescript module in typescript
How might I go about adding the library in a typescript project?
I can provide more details if needed. This was what I could think of including.
tsconfig.jsonfile ? - Jules Sam. Randolph