반응형

1. 시험환경

    · node.js v22, v20, v18

    · npm

    · create-react-app

    · 윈도우

 

2. 목적

    · 리액트 프로젝트 생성(npm create-react-app) 중 발생하는 에러를 해결한다.

    ·  react@19.0.0과 @testing-library/react@13.4.0 간 버전 충돌 회피 방법을 알아보자.

 

3. 적용

    ① npm 명령어를 이용하여 react 프로젝트 생성시 버전 충돌관련 에러가 발생한다.

        - 명령어 : npm  create-react-app  [my-app]   --template  typescript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: notifyapp@0.1.0
npm error Found: react@19.0.0
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/react@13.4.0
npm error node_modules/@testing-library/react
npm error   @testing-library/react@"^13.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
cs

 

    ② 에러의 원인은 create-react-app에서 react 버전이 v19로 설정되지만,  @testing-library는 v18를 요구한다.

        - node.js 버전과 상관없이 발생한다. (node v22, node v20, node v18)


 

    ③ 해결책) 패키지간 버전 관리가 불안정한 npm을 사용하는 대신 yarn을 이용하여 React 프로젝트를 생성하자.

        - 명령어 : yarn  create  react-app  [my-app]  --template  typescript

        - yarn으로 프로젝트 생성 시 패키지 간 버전 호환성에 맞게 설정되는 것을 확인할 수 있다.

 

4. 결과

    · 실행결과를 확인한다.

        - 명령어: yarn  start

 

반응형
반응형

1. 시험환경

    ˙ npm, yarn

    ˙ create-react-app

 

2. 목적

    ˙ yarn을 설치한다.

    ˙ yarn을 이용하여 프로젝트를 생성한다.

    ˙ 개발환경에서 프로젝트를 실행한다.

    ˙ 배포환경으로 프로젝트를 빌드하고 실행한다.

 

3. 적용

    ① npm을 이용하여 yarn을 설치한다.

        - 명령어 : npm install --global yarn

 

 

    ② yarn을 이용하여 현재 디렉토리(.)에 create-react-app을 생성한다.

        - 명령어 : yarn create react-app .

프로젝트 생성 결과

 

    ③ 프로젝트를 실행한다.

        - 명령어 : yarn start

실행결과


    ④ 배포환경으로 프로젝트를 빌드한다.

        - 명령어 : yarn build

빌드 실행결과

 

    ⑤ serve를 설치하고 빌드 디렉토리를 서비스한다.

        - 명령어 : yarn global add serve

        - 명령어 : npx serve [build 결과 디렉토리]

 

4. 결과

    ˙ 개발 소스와 빌드 패키지가 정상 동작되는 것을 확인한다.

 

※ 내용이 도움 되셨다면 광고 클릭 한번 부탁드립니다 ※

반응형

+ Recent posts