fix(tsconfig.json): prevent duplicate tsconfig include entries on Windows #85056
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes an issue where running
npm run dev
on Windows would add duplicate entries to tsconfig.json's include array - one with backslashes (.next\dev/types/**/*.ts
) and one with forward slashes (.next/dev/types/**/*.ts
).The fix normalizes all paths to POSIX-style (forward slashes) using
path.posix
and deduplicates thenextAppTypes
array using a Set before adding entries to tsconfig.json.This solution is cross-platform compatible and works consistently on Windows, macOS, and Linux.
For Contributors
Fixing a bug
fixes #number
writeConfigurationDefaults.test.ts
) covers this functionality and passesWhat?
This PR fixes a Windows-specific bug where duplicate TypeScript config entries were added to
tsconfig.json
'sinclude
array duringnpm run dev
.Why?
On Windows, the
distDir
path separator handling caused the same logical path to appear twice in different formats:.next\dev/types/**/*.ts
(mixed separators from Windows path operations).next/dev/types/**/*.ts
(POSIX-style from string templates)This resulted in duplicate console log messages and duplicate entries in the tsconfig, confusing users.
Changes:
packages/next/src/lib/typescript/writeConfigurationDefaults.ts
Before: Duplicate lines added to tsconfig.json
Console message:
After: tsconfig.json contains single deduplicated path
How?
The fix adds path normalization and deduplication in
writeConfigurationDefaults.ts
:toPosix()
helper that converts all paths to POSIX-style (forward slashes) usingpath.posix.sep
Set
to remove duplicate entries before adding to tsconfigCloses NEXT-
Fixes #85028
-->