microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.26k stars 1.14k forks source link

Get-ChildItem : Cannot find path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community C:\Program Files\Microsoft Visual Studio\2 022\Community\Common7\IDE\Extensions\' because it does not exist. #9260

Closed liudonghua123 closed 2 years ago

liudonghua123 commented 2 years ago

Problem Description

I followed the instruction on https://microsoft.github.io/react-native-windows/docs/getting-started#install-react-native-for-windows, and when I run npx react-native run-windows or yarn start, I got the following errors.

D:\code\react-native\react_native_windows_quickstart>npx react-native run-windows
Get-ChildItem : Cannot find path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community C:\Program Files\Micros
oft Visual Studio\2022\Community\Common7\IDE\Extensions\' because it does not exist.
At D:\code\react-native\react_native_windows_quickstart\node_modules\react-native-windows\Scripts\rnw-dependencies.ps1:
174 char:19
+ ...   $natvis = Get-ChildItem "$vsPath\Common7\IDE\Extensions\cppwinrt.na ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program File...IDE\Extensions\:String) [Get-ChildItem], ItemNotFound
   Exception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

 × Couldn't get app solution information. Couldn't determine Windows app config
Re-run the command with --logging for more information
Your session id was 9653734f6b80e3da7e69f488f32b5d0d

So I go through the rnw-dependencies.ps1:174 and found the problem is $vsPath has two values in my environment.

https://github.com/microsoft/react-native-windows/blob/c7646fa4ae5ca6a6204e7b210b25c30bcdc844ff/vnext/Scripts/rnw-dependencies.ps1#L173-L174

PS C:\Users\Liu.D.H> $vsPath = & $vsWhere -version 16.5 -property installationPath;
PS C:\Users\Liu.D.H> echo $vsPath
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
C:\Program Files\Microsoft Visual Studio\2022\Community
PS C:\Users\Liu.D.H> $natvis = Get-ChildItem "$vsPath\Common7\IDE\Extensions\cppwinrt.natvis" -Recurse;
Get-ChildItem : Cannot find path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community C:\Program Files\Microsoft Visual Studio\2
022\Community\Common7\IDE\Extensions\' because it does not exist.
At line:1 char:11
+ $natvis = Get-ChildItem "$vsPath\Common7\IDE\Extensions\cppwinrt.natv ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Program File...IDE\Extensions\:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

PS C:\Users\Liu.D.H>

If I add a --latest option in vswhere, then it works.

PS C:\Users\Liu.D.H> $vsPath = & $vsWhere -version 16.5 -property installationPath -latest;
PS C:\Users\Liu.D.H> echo $vsPath
C:\Program Files\Microsoft Visual Studio\2022\Community
PS C:\Users\Liu.D.H>

Steps To Reproduce

  1. npx react-native init react_native_windows_quickstart --template react-native@^0.66.0
  2. cd react_native_windows_quickstart
  3. npx react-native-windows-init --overwrite
  4. npx react-native run-windows

Expected Results

work expected as https://microsoft.github.io/react-native-windows/docs/getting-started

CLI version

6.3.0

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
    Memory: 3.13 GB / 15.92 GB
  Binaries:
    Node: 14.18.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.1.3 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 7, 8, 9
      Build Tools: 22.0.1, 23.0.1, 25.0.1, 25.0.2, 25.0.3, 26.0.2, 27.0.0, 27.0.1, 28.0.2, 28.0.3, 29.0.2, 30.0.0, 30.0.2, 31.0.0, 31.0.0
      System Images: android-27 | Google APIs Intel x86 Atom, android-28 | Android TV Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
      Android NDK: 21.3.6528147
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      Versions: 10.0.19041.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.31911.196 (Visual Studio Community 2019), 17.0.31919.166 (Visual Studio Community 2022)
  Languages:
    Java: javac 17 - C:\Program Files\Java\jdk-17\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2
    react-native: 0.66.0 => 0.66.0
    react-native-windows: 0.66.5 => 0.66.5
  npmGlobalPackages:
    *react-native*: Not Found

Target Platform Version

No response

Target Device(s)

Desktop

Visual Studio Version

No response

Build Configuration

No response

Snack, code example, screenshot, or link to a repository

No response

ghost commented 2 years ago

Many of our core contributors are taking some much needed vacation throughout December 2021. Thank you for being patient while we relax, recharge, and return to a normal responsiveness in January 2022. In the meantime feel free to continue to pose questions, open issues, and make feature requests - you just may not get a response right away.

NickGerleman commented 2 years ago

cc @chrisglein @asklar this is the second person who hit the regression that prevents building with multiple versions of Visual Studio. See https://github.com/microsoft/react-native-windows/issues/8471 for the other. Are we providing any support for the dependencies script?

I added a workaround in https://github.com/microsoft/react-native-windows/pull/8571 that silences failures in the dependency script. This will land in 0.67 by default but may be worth backporting to 0.65 and 0.66.

liudonghua123 commented 2 years ago

@NickGerleman Thanks for you resources. Now I add a --latest option in vswhere locally, then everything worked.

 $vsPath = & $vsWhere -version 16.5 -property installationPath --latest; 
chrisglein commented 2 years ago

Seems like adding --latest to the dependency script will handle this. That does mean we might get noise from prerelease builds of VS that we haven't tested yet, although those are issues we'll have to track eventually. It also means there's ability for someone to choose which version they use here (if they don't want latest). But for the most common case, using latest seems like the right case.

NickGerleman commented 2 years ago

Seems like adding --latest to the dependency script will handle this.

This isn't quite correct either. The CLI has logic to locate the latest version of VS that has the required dependencies to install. So the dependencies script could use a different version than the CLI, which would find the correct version.

For the CLI, the powershell script could maybe allow it to pass its own resolved VS path? IMO the script should just be in JS, so it can directly interface with health checks, and the run-windows code we've iterated on to solve these issues more reliably.

asklar commented 2 years ago

the dependencies script cannot be in JS, since it must have an environment to run that JS, which does not exist inbox. Windows developers don't usually have node installed, e.g..

NickGerleman commented 2 years ago

@asklar do you think it would be reasonable to require users to install Node before running the script? I think that is the story for other platforms.

Another option might be for the Powershell dependencies script to "bootstrap" node if not installed but defer to doctor after ensuring we had a valid JS environment. So, basically the dependencies script would become a JS environment installer, to load doctor, which is the RN standard tool.

Anton-Layla commented 2 years ago

@NickGerleman Thanks for you resources. Now I add a --latest option in vswhere locally, then everything worked.

 $vsPath = & $vsWhere -version 16.5 -property installationPath --latest; 

Hi i seem to have the same error

Get-ChildItem : Der Pfad "C:\Common7\IDE\Extensions\" kann nicht gefunden werden, da er nicht vorhanden ist.
In C:\Users\name\Documents\name\name\name\node_modules\react-native-windows\Scripts\rnw-dependencies.ps1:174 Zeichen:19
+ ...   $natvis = Get-ChildItem "$vsPath\Common7\IDE\Extensions\cppwinrt.na ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Visual Studio L...ed.  Error 0x57:String) [Get-ChildItem], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

but sadly the fix from NickGerleman didn't work.

okay i now see it's not entirely the same, for me it's a DriveNotFoundException

I get still the same Error. What i did found, was that the path in line 174 "$vsPath\Common7\IDE\Extensions\cppwinrt.natvis" does not exist, there is no Common7 Folder under ProgramFiles(x86)\Microsoft Visual Studio\Installer\

I will try reinstalling VSCode

"react": "^17.0.2", "react-native": "^0.66.0", "react-native-windows": "^0.66.6", node --version: v16.13.1 yarn --version: 1.22.15 Win 10, 40GB RAM The Node.js Version in VSCode Info is Different

Version: 1.63.2 (user setup)
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Datum: 2021-12-15T09:40:02.816Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
Betriebssystem: Windows_NT x64 10.0.19042
chrisglein commented 2 years ago

@asklar Do we have a solution in mind for this?