React Native

[React Native] TypeError: cli.init is not a function

지니지니하지니 2023. 5. 19. 12:58

프로젝트를 생성할 폴더로 들어와 터미널에서 아래 코드를 입력하는데 TypeError가 발생하였다

npx react-native init projectName
found 0 vulnerabilities
/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:1267:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v20.1.0

 

해당 오류는 React Native의 버전이 맞지 않아 발생한 오류로, 낮은 버전으로 실행하면 정상 작동된다.

npx react-native init projectName --version 0.68.2

 

+24.06.13 추가

전역으로 설치된 CLI를 삭제해주기(전역 설치는 비추천, 프로젝트마다 npx로 init 하는걸 추천)

npm uninstall -g react-native-cli