Node.js 导入后未定义Airtable
我的任务是使用从带有NodeJS的AirTable API获得的数据执行一些工作。我正在使用AirTableJS节点库和DefinitelyTyped airtable定义(我正在使用NestJS) 因此,我自然会执行以下操作来导入必要的包Node.js 导入后未定义Airtable,node.js,typescript,nestjs,airtable,Node.js,Typescript,Nestjs,Airtable,我的任务是使用从带有NodeJS的AirTable API获得的数据执行一些工作。我正在使用AirTableJS节点库和DefinitelyTyped airtable定义(我正在使用NestJS) 因此,我自然会执行以下操作来导入必要的包 yarn add airtable @types/airtable 然后,在与AirTable API交互的存储库中,我有以下内容 import { User } from "../entities/user"; import { ConfigServic
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
}
}
我是否遗漏了任何东西,或者我没有正确导入Airtable软件包
谢谢。它没有定义,因为您没有导入
Airtable
这可能看起来像:
import Airtable, { Base } from "airtable";
您没有从任何地方导入
Airtable
类,因此Node和Tyepscript不知道它是什么。最接近的是从airtable
pacakge导入的Base
类型。由于他们的文档不是公开的,所以很难说如何修复它。我尝试了您的解决方案。而且,它似乎不喜欢我直接导入Airtable,因为它会出现错误:Module“”只能使用'esModuleInterop'标志默认导入。您应该在tsconfig.json
文件中设置“esModuleInterop”:true。许多npm模块要求它使默认导入工作。显然,airtable就是其中之一。或者,您可以尝试从“Airtable”中导入*作为Airtable
或const Airtable=require('Airtable')
。但是esModuleInterop
真的不应该给您带来任何麻烦。好的。谢谢这很有效。我想我应该开始在我的所有项目中将esModuleInterop设置为true,以使事情变得更简单。:)
import Airtable, { Base } from "airtable";