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

Error initializing RNW in a React Native project #9271

Closed qmatteoq closed 2 years ago

qmatteoq commented 2 years ago

Problem Description

When I call npx react-native-windows init --overwrite in a folder which contains a new React Native project, I get the following error:

Reading project name from package.json...
Reading react-native version from node_modules...
Reading react-native version from node_modules...
Latest matching version of react-native-windows for react-native@0.66.0 is react-native-windows@0.66.5
Installing react-native-windows@0.66.5...
warning "react-native > react-native-codegen > jscodeshift@0.11.0" has unmet peer dependency "@babel/preset-env@^7.1.6".
warning "@react-native-community/eslint-config > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
react-native-windows@0.66.5 successfully installed.
Cannot find module 'react-native-windows/local-cli/generate-windows'
Require stack:
- C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\lib-commonjs\requireGenerateWindows.js
- C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\lib-commonjs\Cli.js
- C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\bin.js
Error: Cannot find module 'react-native-windows/local-cli/generate-windows'
Require stack:
- C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\lib-commonjs\requireGenerateWindows.js
- C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\lib-commonjs\Cli.js
- C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\bin.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at requireGenerateWindows (C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\src\requireGenerateWindows.ts:24:33)
    at C:\Users\mpagani\AppData\Local\npm-cache\_npx\966c6a96be6f5a32\node_modules\react-native-windows-init\src\Cli.ts:577:51
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\mpagani\\AppData\\Local\\npm-cache\\_npx\\966c6a96be6f5a32\\node_modules\\react-native-windows-init\\lib-commonjs\\requireGenerateWindows.js',
    'C:\\Users\\mpagani\\AppData\\Local\\npm-cache\\_npx\\966c6a96be6f5a32\\node_modules\\react-native-windows-init\\lib-commonjs\\Cli.js',
    'C:\\Users\\mpagani\\AppData\\Local\\npm-cache\\_npx\\966c6a96be6f5a32\\node_modules\\react-native-windows-init\\bin.js'
  ]
}
Command failed. Re-run the command with --verbose for more information.

If I try to perform the same initialization command again after the error, the second time it works, and Windows support gets added succesfully.

Steps To Reproduce

  1. Create a new React Native project following the Get started instructions.
  2. Add Windows support by executing:
npx react-native-windows-init --overwrite

Expected Results

Windows support is installed without problems immediately, without seeing any error and having to repeat the command twice.

CLI version

6.3.1

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 1.89 GB / 15.60 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.15 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
      Versions: 10.0.17134.0, 10.0.17763.0, 10.0.18362.0, 10.0.19041.0, 10.0.22000.0
  IDEs:
    Android Studio: Not Found
    Visual Studio: 16.11.31911.196 (Visual Studio Enterprise 2019), 17.1.31911.260 (Visual Studio Enterprise 2022), 17.0.31912.275 (Visual Studio Enterprise 2022)
  Languages:
    Java: 1.8.0_302 - C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\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

10.0.19041

Target Device(s)

Desktop

Visual Studio Version

Visual Studio 2019

Build Configuration

Debug

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.

iwater commented 2 years ago

+1

chrisglein commented 2 years ago

Cannot find module 'react-native-windows/local-cli/generate-windows'

In triage hearing that a number of people have also seen this. We should investigate.

asklar commented 2 years ago

I can repro this but I'm not sure yet what's going on. As @qmatteoq mentioned, running it a second time, everything works, but obviously it shouldn't be necessary to run it twice :)

it looks like the init script is falling down a legacy codepath instead of using the 63+ codepath. CC @jonthysell

jonthysell commented 2 years ago

Fix will be out shortly.

asklar commented 2 years ago

published a new npm package, should be fixed now.