김치킨 195
읽고 쓰는 프로그래머
김치킨 195
전체 방문자
오늘
어제
  • 분류 전체보기 (46)
    • 읽다 (1)
    • 쓰다 (12)
      • 자기계발 (6)
      • 지식관리 (1)
      • 글쓰기 (3)
      • 생각 (2)
    • 개발하다 (1)
      • 개발 (1)
    • 기타 (0)

블로그 메뉴

  • 홈
  • 방명록

공지사항

인기 글

태그

  • 리눅스
  • RN
  • wls2
  • 파인만 테크닉
  • docker build
  • Docker
  • 아웃풋 트레이닝
  • 아웃풋트레이닝
  • PM2
  • 리액트네이티브
  • ReactNative
  • 도커
  • vsCode
  • 네트워크 격리
  • 부자들의 초격차 독서법
  • 컨테이너
  • docker images
  • react-native
  • 글쓰기
  • WSL2

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
김치킨 195

읽고 쓰는 프로그래머

[리액트 네이티브/React Native] TypeScript 템플릿 사용시 에러
카테고리 없음

[리액트 네이티브/React Native] TypeScript 템플릿 사용시 에러

2020. 1. 7. 17:15

 

Error 
error An unexpected error occurred: "https://registry.yarnpkg.com/react-native-template-template-typescript: Not found”.
error This module isn't specified in a package.json file.
 
 
react-native cli를 이용해서 프로젝트를 생성할 때 typescript template를 사용할 수 있다. 
 
 
 
 
PC에 react-native cli를 이미 설치했기 때문에 아래와 같이 project를 세팅하려고 했다. 
 
react-native init AwesomeTSProject --template react-native-template-typescript
 
 
하지만 아래와 같은 에러가 뿜뿜...
 
info Setting up new React Native app in /Users/cckn/ws/AwesomeTSProject2
info Fetching template react-native-template-template-typescript...
yarn add v1.21.1
[1/4] 🔍  Resolving packages...
warning jest > jest-cli > jest-config > jest-environment-jsdom > jsdom > left-pad@1.3.0: use String.prototype.padStart()
error An unexpected error occurred: "https://registry.yarnpkg.com/react-native-template-template-typescript: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/Users/cckn/ws/AwesomeTSProject2/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
yarn remove v1.21.1
[1/2] 🗑  Removing module react-native-template-template-typescript...
error This module isn't specified in a package.json file.
info Visit https://yarnpkg.com/en/docs/cli/remove for documentation about this command.
warn Failed to clean up template temp files in node_modules/react-native-template-template-typescript. This is not a critical error, you can work on your app.
(node:10378) UnhandledPromiseRejectionWarning: Error: Command failed: yarn add react-native-template-template-typescript
    at makeError (/Users/cckn/ws/AwesomeTSProject2/node_modules/execa/index.js:174:9)
    at Promise.all.then.arr (/Users/cckn/ws/AwesomeTSProject2/node_modules/execa/index.js:278:16)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:10378) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:10378) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
 
해당 템플릿을 찾을 수 없다고 하는데.. 
 
생성된 폴더를 확인하면 타입스크립트가 아닌 기본 react-native 프로젝트가 생성되어 있다. 
 
npx react-native init AwesomeTSProject --template react-native-template-typescript
 
npx를 이용하면 뭔가 다른가 해서 npx를 이용해 프로젝트 세팅을 해봐도 결과는 마찬가지 
 
 
 

해결책 
 
https://github.com/react-native-community/react-native-template-typescript에서 매뉴얼을 확인했다.
 
 
레거시 react-native-cli에서는 해당 템플릿을 사용할 수 없고 새로운 CLI에서만 사용할 수 있다고 한다. 
 
기존의 cli를 제거하고 npx를 이용하거나 npx를 이용하고 싶지 않다면 새로운 cli를 전역으로 설치해야 한다. 
 
# uninstall legacy cli 
npm uninstall -g react-native-cli
 
# install new cli 
npm i -g @react-native-community/cli
 # or 
yarn global add @react-native-community/cli
 
 
# init typescript project
npx react-native init MyApp --template react-native-template-typescript
 
Done!
 
참조
  • https://facebook.github.io/react-native/docs/getting-started
  • https://github.com/react-native-community/react-native-template-typescript
 
    김치킨 195
    김치킨 195
    읽고, 쓰고, 개발한 기록을 보관합니다.

    티스토리툴바