티스토리 뷰

리액트 네이티브(React Natice) Typescript 템플릿 프로젝트 생성

 

 

리액트 네이티브는 기본적으로 플로우(Flow)라는 정적 타입 분석기를 사용한다.

하지만 문법의 가독성과 편의성 등 여러 장점이 많은 타입스크립트 사용을 권장한다.

 

 

react-natice-cli를 사용한 Typescript templae 프로젝트 생성하기

npx react-native init TypescriptTestApp --template react-native-template-typescript


프로젝트에 필요한 styled, babel 라이브러도 같이 설치해 주자
cd TypescriptTestApp

npm install --save styled-components 
npm install --save-dev @types/styled-components-react-native
npm install --save-dev babel-plugin-root-import
npm install --save-dev @babel/preset-typescript


참고로 레거시 react-native-cli에서는 타입스크립트 템플릿을 사용할 수 없다고 한다

프로젝트 생성 시 아래와 같은 오류가 발생하면

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/react-native-template-react-native-template-typescript - Not found
npm ERR! 404
npm ERR! 404  'react-native-template-react-native-template-typescript@*' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\popoh\AppData\Local\npm-cache\_logs\2022-03-09T08_42_38_890Z-debug-0.log

 

기존의 react-native-cli를 삭제하고 

npm uninstall -g react-native-cli

 

새로은 cli를 다시 설치 후 프로젝트를 하면 된다

npm install -g @react-native-community/cli
반응형
댓글
반응형
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday