Airtable undefined error after importing in Node.js project

Hey everyone, I’m stuck with a weird issue in my Node.js project. I’m trying to use the Airtable API, but I’m getting an error saying Airtable is not defined. Here’s what I did:

  1. Installed packages: yarn add airtable @types/airtable
  2. Imported stuff in my repo file:
import { Base } from "airtable";

// ... other imports and class definition ...

async fetchUnsyncedRecords(): Promise<RecordType[]> {
  const tableConnection: Base = new Airtable({apiKey: this.secretKey}).table(this.tableId);
  // more code here
}

When I run it, I get this error:

ReferenceError: Airtable is not defined

Did I mess up the import somehow? What am I missing here? Thanks for any help!

hey mate, ran into this before. try importing airtable like this:

import Airtable from ‘airtable’

that should fix it. also check ur tsconfig.json, make sure esModuleInterop is set to true. if it still doesnt work, maybe try deleting node_modules and reinstalling everthing. good luck!

I’ve encountered this problem before. The issue is largely due to how Airtable is being imported into your project. Instead of importing just the Base type, you should import the entire Airtable module.

Try this:

import Airtable from 'airtable';

Then, adjust your table connection like this:

const tableConnection = new Airtable({apiKey: this.secretKey}).base(this.baseId)(this.tableId);

Double-check that your package.json lists Airtable and that you’ve run yarn install. A fresh install can sometimes resolve these unexpected errors.

Hope this clears things up and helps get your project running smoothly!

I encountered a similar issue when working with Airtable in a Node.js project. The problem likely stems from how you’re importing Airtable. Instead of importing just the Base type, try importing the entire Airtable module like this:

import Airtable from 'airtable';

Then, you can use it as you’ve shown in your code. This should resolve the ‘Airtable is not defined’ error. Also, make sure your ‘tsconfig.json’ file includes ‘esModuleInterop’ set to true if you’re using TypeScript. This allows for smoother importing of CommonJS modules like Airtable in a TypeScript environment.

If you’re still having issues, double-check that the Airtable package is properly installed in your project’s node_modules directory. Sometimes, a clean install can help resolve unexpected import errors.