react-native-community/cli

Unable to generate a new project using `npx react-native init AwesomeProject`.

PrimeTimeTran opened this issue · 3 comments

Environment

$ npx react-native info                                                                                                                                                      [6:18:28]
info Fetching system and libraries information...
System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 114.38 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/.volta/tools/image/node/18.15.0/bin/node
    Yarn: 3.5.0 - ~/.volta/tools/image/yarn/3.5.0/bin/yarn
    npm: 9.5.0 - ~/.volta/tools/image/node/18.15.0/bin/npm
    Watchman: 2023.04.24.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: Not Found
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.9862592
    Xcode: 14.2/14C18 - /usr/bin/xcodebuild
  Languages:
    Java: javac 20 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.2 => 0.68.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Description

I'm unable to generate a new project using npx react-native init AwesomeProject.

After running the command I get the following error complaining about templates.

✔ Downloading template
✖ Copying template
error Error: Couldn't find the "/var/folders/fh/lhl7dk512g91vhcm4dw5lqjh0000gn/T/rncli-init-template-l54HLn/node_modules/react-native/template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template.
Error: Error: Couldn't find the "/var/folders/fh/lhl7dk512g91vhcm4dw5lqjh0000gn/T/rncli-init-template-l54HLn/node_modules/react-native/template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template
    at createFromTemplate (/Users/loi/.npm/_npx/dea611a43221eddd/node_modules/@react-native-community/cli/build/commands/init/init.js:131:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.initialize [as func] (/Users/loi/.npm/_npx/dea611a43221eddd/node_modules/@react-native-community/cli/build/commands/init/init.js:184:3)
    at async Command.handleAction (/Users/loi/.npm/_npx/dea611a43221eddd/node_modules/@react-native-community/cli/build/index.js:106:9)

Reproducible Demo

There isn't code to share becasue the command only creates a direct named MyAwesomeProject and then immediately exits on encountering that failure.

Please advise. TIA~!

Hello @PrimeTimeTran! Could you please try to create project with this command npx react-native@latest init MyAwesomeProject?

Thanks @szymonrybczak!

I did and it failed with that one as well.

Solution

I just remembered that sometimes npm and yarn conflict.

When running the command npx react-native@latest init AwesomeProject --npm it now works!

atlj commented

I can confirm this issue is only present with newer versions of yarn. @szymonrybczak in order to reproduce this, you can follow https://yarnpkg.com/getting-started/install and install yarn 3.5.0.