Home > OS >  TypeError: cli.init is not a function when npx react-native init
TypeError: cli.init is not a function when npx react-native init

Time:09-21

After upgrading React Native from 0.68.2 to 0.70.1 on MacOS Monterrey M1, npx react-native init my-prom started throwing error:

/opt/homebrew/lib/node_modules/react-native-cli/index.js:302
  cli.init(root, projectName);
      ^

TypeError: cli.init is not a function
    at run (/opt/homebrew/lib/node_modules/react-native-cli/index.js:302:7)
    at createProject (/opt/homebrew/lib/node_modules/react-native-cli/index.js:249:3)
    at init (/opt/homebrew/lib/node_modules/react-native-cli/index.js:200:5)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/react-native-cli/index.js:153:7)
    at Module._compile (node:internal/modules/cjs/loader:1120:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Module._load (node:internal/modules/cjs/loader:839:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

Node.js v18.7.0

npm -g list shows react-native-cli 2.0.1 was installed globally. Remove react-native-cli and install it again global didn't fix the problem. React Native was installed locally.

CodePudding user response:

yarn add react-native --exact

This should be able to fix your problem, don't know exactly why though!

  • Related