DIYgod/RSSHub · error · Error
Failed to find __NEXT_DATA__ script tag in page${url ? `: ${
Error message
Failed to find __NEXT_DATA__ script tag in page${url ? `: ${url}` : ''} What it means
Thrown by the `extractNextData` utility (shared across Hupu routes) when the provided HTML string does not contain a `<script id="__NEXT_DATA__" type="application/json">` tag with JSON content. The function uses a regex to locate this tag. If the upstream Hupu page changed its structure, served a blocked/challenge page, or returned an error page without the Next.js data script, the regex fails to match.
Source
Thrown at lib/routes/hupu/utils.ts:12
import { load } from 'cheerio';
import type { DataItem } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate, parseRelativeDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export function extractNextData<T = unknown>(html: string, url?: string): T {
const scriptMatch = html.match(/<script id="__NEXT_DATA__" type="application\/json">(.*?)<\/script>/);
if (!scriptMatch || !scriptMatch[1]) {
throw new Error(`Failed to find __NEXT_DATA__ script tag in page${url ? `: ${url}` : ''}`);
}
try {
return JSON.parse(scriptMatch[1]) as T;
} catch (error) {
throw new Error(`Failed to parse __NEXT_DATA__ JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
}
}
interface ThreadNextData {
props: {
pageProps: {
threadData: {
data: {
moduleConfigList: {
content: {
moduleContent: {
content: string;View on GitHub (pinned to bed535e087)
Solutions
- Open the failing URL in a browser to see what HTML is actually returned.
- If a CAPTCHA/anti-bot page is returned, consider using `config.trueUA` or adding Puppeteer-based fetching.
- If a specific thread URL is dead, this is transient and the cache will eventually expire.
- If the site migrated, update the parsing logic in `extractNextData` and its callers.
Defensive patterns
Strategy: try-catch
Type guard
function hasNextDataScript(html: string): boolean {
return /<script id="__NEXT_DATA__" type="application\/json">/.test(html);
} Try / catch
try {
const data = extractNextData<T>(html, url);
return data;
} catch (err) {
// Log the HTML length and first N chars for diagnosis without surfacing to users
throw new Error(`Could not extract Next.js data from ${url}: ${err instanceof Error ? err.message : String(err)}`);
} Prevention
- Monitor upstream site structure changes.
- Use `config.trueUA` for realistic browser headers to avoid anti-bot challenge pages.
- Cache successfully parsed pages to reduce re-fetch exposure.
- Consider falling back to Puppeteer for pages that serve different HTML to server-side clients.
When it happens
Trigger: The Hupu page served to RSSHub does not contain the expected `__NEXT_DATA__` script tag — this happens when the site is under maintenance, returns a CAPTCHA/anti-bot challenge, changes its SSR framework, or the specific page (e.g. a deleted thread) returns a 404 error page without Next.js data.
Common situations: Hupu deploys anti-bot protection that serves a different HTML to server-side fetchers, a thread was deleted and the URL returns a custom 404, the site migrated away from Next.js, or the RSSHub instance's IP is rate-limited.
Related errors
- Expected '${dataKey}' property not found in pageProps for ca
- Failed to parse __NEXT_DATA__ JSON: ${error instanceof Error
- Failed to extract Algolia credentials from iapp.org
- 无法解析页面数据,请检查漫画 ID 是否正确或页面结构是否变动
- 无法解析页面 HTML 数据,可能触发了反爬策略或页面结构巨变
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/778b843a84d3e906.
Report an issue: GitHub.