我被赋予了这个任务,用NodeJS对从AirTable应用程序接口获得的数据执行一些操作。我使用的是AirTableJS节点库和DefinitelyTyped airtable定义(我使用的是NestJS)。
因此,我自然会执行以下操作来导入所需的包。
yarn add airtable @types/airtable然后,在与AirTable应用编程接口交互的存储库中,我有以下内容。
import { User } from "../entities/user";
import { ConfigService } from "@nestjs/config";
import { Inject, Injectable } from "@nestjs/common";
import { LogService } from "src/log/services/log/log.service";
import { Base } from "airtable";
@Injectable()
export class UsersRepository {
private readonly apiKey: string;
private readonly baseId: string;
constructor(@Inject(ConfigService) private readonly config: ConfigService, @Inject(LogService) private readonly log: LogService) {
this.apiKey = this.config.get<string>('airtable.apiKey');
this.baseId = this.config.get<string>('airtable.baseId');
}
async getUnmatchedUsers(): Promise<User[]> {
const base: Base = new Airtable({apiKey: this.apiKey}).base(this.baseId);
// other code here
}
}但是,在运行它时,我得到了以下与存储库函数相关的错误:
ReferenceError: Airtable is not defined我是不是遗漏了什么,或者我没有正确导入Airtable包?
谢谢。
发布于 2020-04-30 03:52:23
未定义它,因为您尚未导入Airtable。
这可能看起来像这样:
import Airtable, { Base } from "airtable";发布于 2020-04-30 03:52:23
您没有从任何地方导入Airtable类,所以Node和Tyepscript根本不知道它是什么。最接近的是从airtable包导入的Base类型。由于他们的文档不是公开的,所以很难说如何修复它。
https://stackoverflow.com/questions/61509670
复制相似问题