导入后未定义 Airtable

Airtable not defined after import

我的任务是使用 NodeJS 从 AirTable API 获得的数据执行一些操作。我正在使用带有 DefinitelyTyped airtable 定义的 AirTableJS 节点库(我正在使用 NestJS)。

所以,很自然地,我执行以下操作来导入必要的包。

yarn add airtable @types/airtable

然后,在我与 AirTable API 交互的存储库中,我有以下内容。

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 包?

谢谢。

未定义,因为您尚未导入 Airtable

这可能看起来像:

import Airtable, { Base } from "airtable";

您没有从任何地方导入 Airtable class,因此 Node 和 Tyepscript 不知道它是什么。最接近的是从 airtable 包导入的 Base 类型。由于他们的文档不是 public,所以很难说如何修复它。