Skip to content

fix(static-paths): improve error message for invalid path type in getStaticPaths#95887

Open
dev-shubham01 wants to merge 2 commits into
vercel:canaryfrom
dev-shubham01:fix/getstaticpaths-non-string-error
Open

fix(static-paths): improve error message for invalid path type in getStaticPaths#95887
dev-shubham01 wants to merge 2 commits into
vercel:canaryfrom
dev-shubham01:fix/getstaticpaths-non-string-error

Conversation

@dev-shubham01

Copy link
Copy Markdown

What?

Added a type check in buildPagesStaticPaths to catch when a non-string,
non-object value (e.g. a number) is returned as a path entry in the paths
array from getStaticPaths.

Why?

When a developer forgets to convert a value to a string (e.g. returning a
number from pagination data), the error thrown was confusing and didn't
explain how to fix it. This change throws a clear, actionable error message
pointing to the exact problem.

How?

Added an else if branch in the toPrerender.forEach loop in
packages/next/src/build/static-paths/pages.ts that checks if an entry
is neither a string nor a valid object, and throws a descriptive error
with a hint to convert the value to a string.

Fixes #41281

// For the object-provided path, we must make sure it specifies all
// required keys.
else {
else if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else if (... || entry === null || ...) validation branch in buildPagesStaticPaths produces a TypeScript TS2367 error and prettier violations, breaking the type-check/build.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent Error Messaging / Handling in getStaticPaths

1 participant