vercel/analytics

script.js doesn't load with Next.js Dyamic Routes? [Error on build only]

mitchuman opened this issue · 2 comments

When using Next.js Dynamic Routes (setup found here and just below), /_vercel/insights/* does not seem to get included in the build, thus the analytics scripts aren't running.

Setup: /app/[slug]/page.tsx

Notice the usage of notFound() and generateStaticParams() that likely disable generated routes that aren't included in the fetched data, including /_vercel/*

export default async function Page({ params }: Props) {
	const page = await getPage(params)
	if (!page) notFound()
	return <>...</>
}

export async function generateMetadata({ params }: Props) {
	const page = await getPage(params)
	if (!page) notFound()
	return { ... }
}

export async function generateStaticParams() {
	const slugs = await fetchData(...)
	return slugs.map((slug) => ({ slug }))
}

Local dev (no issue):
Screenshot 2024-06-07 at 2 08 26 PM

after npm run build:
Screenshot 2024-06-07 at 2 04 15 PM

Hey!
Vercel Analytics only works when deployed on Vercel (or when running dev).

Ok I see it running now when I deploy on the live branch. TY