React Native I created an application that reported an error, TypeError: cli.init is not a function ?
How do I fix this error ? See the error below:
JavaScript
D:\>npx react-native init demotsx
This will walk you through creating a new React Native project in D:\demotsx
'yarn' is not recognized as an internal or external command,
operable program or batch file.
Installing react-native...
Consider installing yarn to make this faster:
npm WARN deprecated @babel/plugin-proposal-optional-catch-binding@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.
npm WARN deprecated @babel/plugin-proposal-numeric-separator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.
npm WARN deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
npm WARN deprecated @babel/plugin-proposal-class-properties@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
npm WARN deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
npm WARN deprecated @babel/plugin-proposal-object-rest-spread@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
npm WARN deprecated @babel/plugin-proposal-async-generator-functions@7.20.7: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
added 600 packages, and audited 601 packages in 54s
45 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
C:\Users\win10\AppData\Roaming\npm\node_modules\react-native-cli\index.js:302
cli.init(root, projectName);
^
TypeError: cli.init is not a function
at run (C:\Users\win10\AppData\Roaming\npm\node_modules\react-native-cli\index.js:302:7)
at createProject (C:\Users\win10\AppData\Roaming\npm\node_modules\react-native-cli\index.js:249:3)
at init (C:\Users\win10\AppData\Roaming\npm\node_modules\react-native-cli\index.js:200:5)
at Object. (C:\Users\win10\AppData\Roaming\npm\node_modules\react-native-cli\index.js:153:7)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v20.12.1
Tahir AnsariRank #366 · 6.8K reputationPosted Apr 9, 2024, 4:44 AM EDT
Reinstall React Native CLI: Try reinstalling the React Native CLI globally using npm:
Bohdan StupakRank #479 · 5.2K reputationPosted Apr 11, 2024, 11:07 AM EDT
A slightly more elaborate version of Mohammad's answer
Need to clean global environments with following commands:
install new react-native global
then you can run:
npx react-native init ProjectNameDong Lam TrienRank #1,537 · 1K reputationPosted Apr 11, 2024, 9:47 PM EDT
Hi Bohdan Stupak !
I have created the application, thank you for guiding me to fix the error, but there is still a small error line, does it have any effect? -> "Could not create an empty Git repository, see debug logs with --verbose" below is the error correction process I copied them
D:\aRN>npm uninstall -g react-native up to date in 921ms D:\aRN>npm uninstall -g react-native-cli removed 89 packages in 855ms D:\aRN>npm -g list C:\Users\win10\AppData\Roaming\npm +-- expo-cli@ +-- [email protected] `-- [email protected] D:\aRN>npm install -g react-native-cli added 89 packages in 9s 41 packages are looking for funding run `npm fund` for details D:\aRN>npm install -g react-native npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead. npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead. npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead. npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead. npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead. npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead. npm WARN deprecated @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead. added 600 packages in 1m 45 packages are looking for funding run `npm fund` for details D:\aRN>npx react-native init demotsx ###### ###### ### #### #### ### ## ### ### ## ## #### ## ## #### ## ## ## ## ## ## ### ### ## ## ######################## ## ###### ### ### ###### ### ## ## ## ## ### ### ## ### #### ### ## ### ## #### ######## #### ## ## ### ########## ### ## ## #### ######## #### ## ### ## ### #### ### ## ### ### ## ## ## ## ### ###### ### ### ###### ## ######################## ## ## ### ### ## ## ## ## ## ## #### ## ## #### ## ## ### ### ## ### #### #### ### ###### ###### Welcome to React Native! Learn once, write anywhere v Downloading template v Copying template v Installing dependencies × Could not create an empty Git repository, see debug logs with --verbose Run instructions for Android: • Have an Android emulator running (quickest way to get started), or a device connected. • cd "D:\aRN\demotsx" && npx react-native run-android Run instructions for Windows: • See https://aka.ms/ReactNativeGuideWindows for the latest up-to-date instructions.Dong Lam TrienRank #1,537 · 1K reputationPosted Apr 10, 2024, 3:51 AM EDT
Hi Mohammad Tahir Ansari !
I followed your instructions but it didn't work
Bohdan StupakRank #479 · 5.2K reputationPosted Apr 12, 2024, 8:26 AM EDT
I cannot be 100% sure what's the error now, since --verbose output is missing. But I assume that either git is misconfigured or it is absent. Anyways it does not hinder local development and you can put your project under version control manually later
Dong Lam TrienRank #1,537 · 1K reputationPosted Apr 14, 2024, 10:03 PM EDT
There is one more question I want to ask you, when creating a TypeScript application when running the command: npm start, does it not support scanning QR codes to use the real machine ? What additional packages can I install to get QR codes ?