Skip to content

Fix: Improve error messages for non-string values in getStaticPaths#92991

Open
nikitanagar08 wants to merge 4 commits intovercel:canaryfrom
nikitanagar08:fix/issue-41281-getstaticpaths-validation
Open

Fix: Improve error messages for non-string values in getStaticPaths#92991
nikitanagar08 wants to merge 4 commits intovercel:canaryfrom
nikitanagar08:fix/issue-41281-getstaticpaths-validation

Conversation

@nikitanagar08
Copy link
Copy Markdown

Fixes #41281

Enhanced error messaging for getStaticPaths with non-string parameter values.

Fixes vercel#53473

The `@next/next/no-html-link-for-pages` ESLint rule now respects the
custom `pageExtensions` configuration from Next.js.

Previously, the rule only detected files with hardcoded extensions
(.js, .jsx, .ts, .tsx), causing false positives when using custom
page extensions like `.page.tsx`.

Changes:
- Added second option to rule schema for pageExtensions array
- Modified parseUrlForPages() and parseUrlForAppDir() to accept custom extensions
- Updated file matching regex to use configured pageExtensions
- Default extensions remain ['tsx', 'ts', 'jsx', 'js'] for backward compatibility

Usage:
```js
// eslint.config.js
{
  rules: {
    '@next/next/no-html-link-for-pages': ['error', 'pages', ['.page.tsx']]
  }
}
```
Fixes vercel#41281

Enhanced error messaging when getStaticPaths receives non-string
parameter values, providing clearer guidance on how to fix the issue.

Previously, errors like "received number in getStaticPaths" were not
immediately actionable. Now users get a clear explanation:
- What type was expected (string)
- What type was received (number, boolean, etc.)
- How to fix it (convert to string)

Example improvements:
- Before: "received number in getStaticPaths for /articles/[id]"
- After: "Expected: string (e.g., "123")\nReceived: number (e.g., 123).
         Make sure to convert to string: String(123)"

Changes:
- Added detailed type validation error messages
- Included conversion examples for common types
- Added link to documentation for more information
Comment thread packages/next/src/build/static-paths/pages.ts Outdated
Fix the nested template literal syntax in the error message for
non-string parameter values. The previous version had incorrect
closing syntax that caused a parse error.
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