【发布时间】:2018-08-24 10:09:21
【问题描述】:
编辑:
对于有同样问题的其他人 - 在课堂主体中使用 const Logging: any = require('@google-cloud/logging') 和 var logger = Logging() 就像一个魅力!
记得使用var logger = Logging() 来实例化记录器库。否则你仍然会得到 logger.log is not a function!
原帖
我有一个 firebase 函数项目,用 typescript 编写 - 使用 webpack 编译。我目前正在尝试实现 @google-cloud/logging 库,但我遇到了问题。它出来说
找不到模块“google-cloud/logging”的声明文件。尝试
npm install @types/@google-cloud/logging(如果存在)或添加包含declare module '@google-cloud/logging';的新声明(.d.ts)文件
我尝试通过以下方式添加库:
import * as Logging from '@google-cloud/logging';
import * as logging from '@google-cloud/logging';
import { Logging } from '@google-cloud/logging';
但我仍然收到此错误。尝试运行使用“日志记录”的函数会导致
logging.log 不是函数
我什至尝试过需要库的javascript方式,但仍然没有成功。
我的 tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "./",
"noImplicitAny": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
我读到有些人通过手动将“d.ts”文件添加到项目中取得了成功,尽管我不太了解它。这是堆栈溢出文章的链接-Importing non-typescript module in typescript
如何在打字稿项目中添加库?
如果需要,我可以提供更多详细信息。这是我能想到的。
【问题讨论】:
-
你的构建工具是什么(typesript 编译器、webapck、rollup、gulp、fusebox ...)?你的
tsconfig.json文件是什么?
标签: typescript firebase google-cloud-functions google-cloud-logging