Thanks for pointing it out. I looked into it a bit more, and it seems like the error isn’t coming from next build directly — it’s likely happening during my custom RSS generation script that runs before the build.
Here’s how I run it in package.json:
"build": "pnpm run generate-rss && next build",
"generate-rss": "npx tsx src/scripts/generate-rss.ts"
generate-rss.ts
import { generateRSS } from '../components/lib/rss';
import fs from 'fs';
import path from 'path';
async function main() {
const rss = generateRSS();
const outputPath = path.join(__dirname, '../../public');
fs.mkdirSync(outputPath, { recursive: true });
fs.writeFileSync(path.join(outputPath, 'feed.xml'), rss);
}
And here’s a snippet from generateRSS()
import RSS from 'rss';
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import { CommonMetaData } from './constant';
export const generateRSS = () => {
const feed = new RSS({
title: CommonMetaData.title.default,
description: CommonMetaData.description,
site_url: CommonMetaData.metadataBase.toString(),
feed_url: CommonMetaData.metadataBase.toString() + 'feed.xml',
pubDate: new Date(),
});
const pages = fs.readdirSync(path.join('src/mdx/pages'));
pages.forEach((file) => {
const content = fs.readFileSync(path.join('src/mdx/pages', file), 'utf-8');
const { data: frontMatter } = matter(content);
feed.item({
title: frontMatter.title,
description: frontMatter.description,
url: `${CommonMetaData.metadataBase}pages/${file.replace('.mdx', '')}`,
date: new Date(frontMatter.date),
});
});
return feed.xml();
};
As you can see, nothing fancy — just file reads, frontmatter parsing, and RSS XML writing.
Locally everything works fine, but the deployed environment throws an error.
I’d appreciate it if you could tell me how to debug it. Should I give you my build link by any chance?