I’m working on a Next.js application and trying to fetch data from Airtable inside the getServerSideProps function. However, I keep getting this error whenever I try to import the Airtable library.
Here’s my code setup:
pages/dataPage.js
import React from 'react';
import Airtable from 'airtable';
export const config = {
runtime: 'experimental-edge',
};
export async function getServerSideProps({ params }) {
Airtable.configure({
endpointUrl: 'https://api.airtable.com',
apiKey: process.env.AIRTABLE_KEY,
});
const database = Airtable.base(process.env.AIRTABLE_DATABASE);
const records = database('myTable').select({});
return {
props: {
data: []
}
};
}
function DataPage(props) {
return (
<div>
<h1>My Data</h1>
</div>
);
}
export default DataPage;
The error message I get is:
Error: URL is malformed "". Please use only absolute URLs
I’ve tried setting the endpoint URL explicitly but that didn’t help. The strange thing is that just importing Airtable causes this issue, even without calling any functions. It seems to be related to the experimental edge runtime configuration.
Has anyone successfully used Airtable with Next.js in this setup? What am I missing here?