Skip to content

Commit 975ff30

Browse files
authored
Fix playground composition for Node.js 24.x (#15983)
* Fix project compilation * Fix "yarn start" * Change files * Fix JS issues in Node.js 24.x * Fix other related code * Use process.cwd drive letter instead
1 parent ab59636 commit 975ff30

13 files changed

Lines changed: 103 additions & 23 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Fix project compilation",
4+
"packageName": "react-native-windows",
5+
"email": "vmorozov@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/playground/metro.config.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@ const {makeMetroConfig} = require('@rnw-scripts/metro-dev-config');
99
const fs = require('fs');
1010
const path = require('path');
1111

12-
const rnwPath = fs.realpathSync(
12+
// On Windows, require.resolve through symlinks (e.g. yarn workspace links) can
13+
// return paths with a different drive letter case than process.cwd(). Metro's
14+
// file system lookup is case-sensitive, so we normalize to match cwd.
15+
function normalizePathDrive(p) {
16+
if (process.platform === 'win32' && p.length >= 2 && p[1] === ':') {
17+
return process.cwd()[0] + p.slice(1);
18+
}
19+
return p;
20+
}
21+
22+
const rnwPath = normalizePathDrive(fs.realpathSync(
1323
path.dirname(require.resolve('react-native-windows/package.json')),
14-
);
24+
));
1525

16-
const rnwTesterPath = fs.realpathSync(
26+
const rnwTesterPath = normalizePathDrive(fs.realpathSync(
1727
path.dirname(require.resolve('@react-native-windows/tester/package.json')),
18-
);
28+
));
1929

2030
const devPackages = {
2131
'react-native': path.normalize(rnwPath),
@@ -144,8 +154,25 @@ function tryResolveDevRelativeImport(
144154
return null;
145155
}
146156

147-
module.exports = makeMetroConfig({
157+
const baseConfig = makeMetroConfig({
148158
resolver: {
149159
resolveRequest: devResolveRequest,
150160
},
151161
});
162+
163+
// The getModulesRunBeforeMainModule paths (from @rnx-kit/metro-config) may have
164+
// wrong drive letter case on Windows due to require.resolve through symlinks.
165+
// Metro compares these paths via strict equality against module paths in the
166+
// bundle graph, so the case must match exactly.
167+
const originalGetModulesRunBeforeMainModule =
168+
baseConfig.serializer.getModulesRunBeforeMainModule;
169+
baseConfig.serializer = {
170+
...baseConfig.serializer,
171+
getModulesRunBeforeMainModule: (...args) => {
172+
return originalGetModulesRunBeforeMainModule(...args).map(p =>
173+
normalizePathDrive(fs.realpathSync(p)),
174+
);
175+
},
176+
};
177+
178+
module.exports = baseConfig;

packages/playground/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.0.54",
44
"private": true,
55
"scripts": {
6-
"start": "npx @react-native-community/cli rnx-start",
6+
"start": "react-native rnx-start",
77
"lint:fix": "rnw-scripts lint:fix",
88
"lint": "rnw-scripts lint",
9-
"windows": "npx @react-native-community/cli run-windows"
9+
"windows": "react-native run-windows"
1010
},
1111
"dependencies": {
1212
"@react-native-picker/picker": "2.11.0",

packages/playground/windows/playground-composition.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ EndProject
2929
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Include", "..\..\..\vnext\include\Include.vcxitems", "{EF074BA1-2D54-4D49-A28E-5E040B47CD2E}"
3030
EndProject
3131
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleCustomComponent", "..\..\sample-custom-component\windows\SampleCustomComponent\SampleCustomComponent.vcxproj", "{A8DA218C-4CB5-48CB-A9EE-9E6337165D07}"
32+
ProjectSection(ProjectDependencies) = postProject
33+
{F7D32BD0-2749-483E-9A0D-1635EF7E3136} = {F7D32BD0-2749-483E-9A0D-1635EF7E3136}
34+
EndProjectSection
3235
EndProject
3336
GlobalSection(SharedMSBuildProjectFiles) = preSolution
3437
..\..\..\vnext\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9

vnext/Directory.Build.targets

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,29 @@
44
<!-- This import will noop when customer code is built. This import is here to help building the bits in the react-native-windows repository. -->
55
<Import Condition="Exists($([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../')))" Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
66

7-
<!--Allow implicitly restoring NuGet dependencies in C++ projects using the Visual Studio IDE.-->
8-
<Target Name="BeforeResolveReferences" Condition="'$(BuildingInsideVisualStudio)' == 'true' AND '$(MSBuildProjectExtension)' == '.vcxproj'">
7+
<!--
8+
Allow implicitly restoring NuGet dependencies in C++ and C# projects using the Visual Studio IDE.
9+
10+
For vcxproj: VS does not automatically restore PackageReference or packages.config dependencies.
11+
For csproj referencing vcxproj: VS's NuGet restore cannot evaluate vcxproj PackageReferences
12+
through the project reference chain (the VC project system does not report them via the CPS
13+
nomination API), causing NU1004 lock file mismatches. An explicit msbuild /t:Restore during
14+
the build resolves this because msbuild loads VCTargets and evaluates vcxproj fully.
15+
-->
16+
<Target Name="BeforeResolveReferences" Condition="'$(BuildingInsideVisualStudio)' == 'true' AND ('$(MSBuildProjectExtension)' == '.vcxproj' OR '$(MSBuildProjectExtension)' == '.csproj')">
917
<!--
1018
Ensure restoring of PackageReference dependencies.
1119
-->
1220
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Restore" Properties="RestoreProjectStyle=PackageReference" Condition="@(PackageReference->Count()) &gt; 0" />
1321

1422
<!--
15-
Ensure restoring of packages.config dependencies.
23+
Ensure restoring of packages.config dependencies (vcxproj only).
1624
1725
RestoreProjectStyle=PackagesConfig - Required to use the packages.config mechanism
1826
RestorePackagesConfig=true - Required to use the packages.config mechanism
1927
RestoreUseStaticGraphEvaluation=false - Override setting from Directory.Build.props
2028
-->
21-
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Restore" Properties="RestoreProjectStyle=PackagesConfig;RestorePackagesConfig=true;RestoreUseStaticGraphEvaluation=false" />
29+
<MSBuild Projects="$(MSBuildProjectFile)" Targets="Restore" Properties="RestoreProjectStyle=PackagesConfig;RestorePackagesConfig=true;RestoreUseStaticGraphEvaluation=false" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'" />
2230
</Target>
2331

2432
<!-- This ensures NuGet restores use the nuget config's feed and not any pre-installed files. -->

vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@
411411
</PreprocessorDefinitions>
412412
</ResourceCompile>
413413
</ItemGroup>
414-
<ItemGroup>
415-
<Natvis Include="$(ExternalDir)folly\Folly.natvis" />
416-
</ItemGroup>
417414
<ItemGroup>
418415
<ProjectReference Include="..\Common\Common.vcxproj">
419416
<Project>{fca38f3c-7c73-4c47-be4e-32f77fa8538d}</Project>

vnext/PropertySheets/Autolink.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<PropertyGroup>
99
<RunAutolinkCheck Condition="'$(RunAutolinkCheck)' == ''">true</RunAutolinkCheck>
10-
<AutolinkCommand Condition="'$(AutolinkCommand)' == ''">npx --yes @react-native-community/cli autolink-windows</AutolinkCommand>
10+
<AutolinkCommand Condition="'$(AutolinkCommand)' == ''">npx --yes --no-workspaces @react-native-community/cli autolink-windows</AutolinkCommand>
1111
<AutolinkCommandWorkingDir Condition="'$(AutolinkCommandWorkingDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(ProjectDir), 'package.json'))</AutolinkCommandWorkingDir>
1212
<AutolinkCommandArgs Condition="'$(AutolinkCommandArgs)' == '' And '$(SolutionPath)' != '' And '$(SolutionPath)' != '*Undefined*' And '$(ProjectPath)' != ''">--check --sln "$([MSBuild]::MakeRelative($(AutolinkCommandWorkingDir), $(SolutionPath)))" --proj "$([MSBuild]::MakeRelative($(AutolinkCommandWorkingDir), $(ProjectPath)))"</AutolinkCommandArgs>
1313
<AutolinkCommandArgs Condition="'$(AutolinkCommandArgs)' == ''">--check</AutolinkCommandArgs>

vnext/PropertySheets/Bundle.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<BundlerExtraArgs Condition="'$(BundlerExtraArgs)' == ''">--minify false</BundlerExtraArgs>
4040

4141
<!-- Command to use to create a bundle -->
42-
<BundleCliCommand Condition="'$(BundleCliCommand)' == ''">npx @react-native-community/cli bundle</BundleCliCommand>
42+
<BundleCliCommand Condition="'$(BundleCliCommand)' == ''">npx --yes --no-workspaces @react-native-community/cli bundle</BundleCliCommand>
4343

4444
<!-- This should be the app package root, this is where the bundle command will be run from -->
4545
<BundleCommandWorkingDir Condition="'$(BundleCommandWorkingDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(ProjectDir), 'package.json'))</BundleCommandWorkingDir>

vnext/PropertySheets/Codegen.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<PropertyGroup>
99
<RunCodegenWindows Condition="'$(RunCodegenWindows)' == ''">true</RunCodegenWindows>
10-
<CodegenCommand Condition="'$(CodegenCommand)' == ''">npx --yes @react-native-community/cli codegen-windows</CodegenCommand>
10+
<CodegenCommand Condition="'$(CodegenCommand)' == ''">npx --yes --no-workspaces @react-native-community/cli codegen-windows</CodegenCommand>
1111
<CodegenCommandWorkingDir Condition="'$(CodegenCommandWorkingDir)' == ''">$([MSBuild]::GetDirectoryNameOfFileAbove($(ProjectDir), 'package.json'))</CodegenCommandWorkingDir>
1212
<CodegenCommandArgs Condition="'$(CodegenCommandArgs)' == ''">--logging</CodegenCommandArgs>
1313
</PropertyGroup>

vnext/PropertySheets/NuGet.LockFile.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
<PropertyGroup>
1111
<RestoreLockedMode Condition="'$(RestoreLockedMode)'=='' OR '$(BuildingInRnwRepo)'=='true'">true</RestoreLockedMode>
12+
<!--
13+
VS's NuGet restore cannot evaluate vcxproj PackageReferences through the project reference
14+
chain (the VC project system does not report them via the CPS nomination API). This causes
15+
NU1004 lock file mismatches for csproj files that reference vcxproj. Disable locked mode
16+
in VS so the initial restore succeeds and package targets load correctly.
17+
CI is unaffected: it passes /p:RestoreLockedMode=true as a global property which overrides this.
18+
-->
19+
<RestoreLockedMode Condition="'$(BuildingInsideVisualStudio)' == 'true' AND '$(MSBuildProjectExtension)' == '.csproj'">false</RestoreLockedMode>
1220

1321
<NuGetLockFileName>packages</NuGetLockFileName>
1422
<NuGetLockFileName Condition="'$(UseExperimentalWinUI3)'=='true'">$(NuGetLockFileName).experimentalwinui3</NuGetLockFileName>

0 commit comments

Comments
 (0)