I’m working on a Next.js project and trying to fetch data from Airtable inside the getServerSideProps function. However, I keep getting this weird error about malformed URLs even though I’m not using any relative URLs.
Error: URL is malformed "". Please use only absolute URLs
This happens when I run npm run dev. The error disappears completely when I remove the Airtable import and related code.
I tried moving the configuration outside of getServerSideProps but that didn’t help. I also made sure to set the endpoint URL explicitly but the problem persists.
What’s really strange is that just importing the Airtable library causes this issue, even without calling any functions. It seems like this might be connected to the experimental edge runtime I’m using.
Has anyone encountered this before? How can I successfully use Airtable with Next.js server-side rendering?
export async function getServerSideProps(context) {
const { getAirtableBase } = await import('../lib/airtable');
const database = getAirtableBase();
// rest of your code
}
This keeps the library separate so the bundler doesn’t try to process it upfront. Just make sure you remove the edge runtime config first - stick with default nodejs for this to work.