Airtable import causing undefined reference error

I’m working on a project that needs to fetch data from Airtable using Node.js. I’m using the airtable npm package along with TypeScript definitions in a NestJS application.

First I installed the required packages:

npm install airtable @types/airtable

Then I created a service to handle the Airtable operations:

import { Customer } from "../models/customer";
import { ConfigService } from "@nestjs/config";
import { Inject, Injectable } from "@nestjs/common";
import { LoggerService } from "src/logger/services/logger.service";
import { Base } from "airtable";

@Injectable()
export class CustomerService {
    private readonly token: string;
    private readonly databaseId: string;

    constructor(
        @Inject(ConfigService) private readonly configService: ConfigService,
        @Inject(LoggerService) private readonly logger: LoggerService
    ) {
        this.token = this.configService.get<string>('airtable.token');
        this.databaseId = this.configService.get<string>('airtable.databaseId');
    }

    async fetchPendingCustomers(): Promise<Customer[]> {
        const database: Base = new Airtable({apiKey: this.token}).base(this.databaseId);
        // additional logic here
    }
}

However, when I try to run this code, I get an error:

ReferenceError: Airtable is not defined

What could be wrong with my import statement? Is there something I’m missing in the setup?

You’re mixing import styles here. You imported Base as a named import but you’re trying to use Airtable as a constructor. Pick one approach and stick with it. Either do import Airtable, { Base } from 'airtable' to get both, or just use const database = new Base('your-base-id') after you’ve set up Airtable.configure() with your API key. I hit the same thing with TypeScript and older npm packages that weren’t built for ES modules.

This is a module compilation issue. Your import looks fine, but the error means the module isn’t resolving properly at runtime.

I hit this exact problem when we migrated our data pipeline to TypeScript. Airtable’s package has weird export quirks.

Try using require instead:

const Airtable = require('airtable');

Then set it up once in your constructor:

constructor(
    @Inject(ConfigService) private readonly configService: ConfigService,
    @Inject(LoggerService) private readonly logger: LoggerService
) {
    this.token = this.configService.get<string>('airtable.token');
    this.databaseId = this.configService.get<string>('airtable.databaseId');
    
    Airtable.configure({ apiKey: this.token });
}

async fetchPendingCustomers(): Promise<Customer[]> {
    const database = Airtable.base(this.databaseId);
    // your logic
}

This skips the import mess and works reliably across different Node environments. We’ve used this pattern for two years with zero issues.

Had this exact problem with Airtable in NestJS last month. You’re importing it wrong - needs to be a default import, not named. Change import { Base } from "airtable" to import Airtable from "airtable" or just use const Airtable = require('airtable') if you want CommonJS. The @types/airtable package expects default export. You might also need "esModuleInterop": true in your tsconfig.json if it’s not there already - helps TypeScript handle mixed CommonJS and ES modules. That should fix your constructor.

Check your TypeScript config - module resolution can break default imports. Try import * as Airtable from 'airtable' instead. Fixed it for me when the regular default import didn’t work. Also verify your Node version matches what the Airtable package needs. I’ve gotten weird undefined errors from version mismatches.