npx react-react-app 실행시 react-scripts 0.9.5로 설치되는 현상 수정

김병훈·2023년 4월 16일

nodejs

목록 보기
2/2

동일한 문제에 대한 GitHub 문의글 바로가기

사용환경.

Ubuntu Desktop 22.04.2 LTS

문제.

우분투에서 'npx create-react-app hello-react' 을 통해 react 프로젝트 생성시 react-scripts: 0.9.5 로 설치 되는 현상.

원인.

  1. 여러버전의 node를 설치한 경우.
  2. npm -g로 글로벌 옵션으로 설치한 경우.
  3. 우분투의 'Ubuntu Software' 스토어를 통해 node를 설치한 경우.

해결.

node를 삭제 후 다시 설치하면 react-scripts: 5.0.1 과 같이 정상적으로 설치됨.
가급적 콘솔을 통한 직접 설치 권장.

node 삭제

  1. 터미널 실행
  2. root 권한 획득 후 3번 명령어 실행(sudo su)
  3. npm ls -gp --depth=0 | awk -F/ '/node_modules/ && !/\/npm$/ {print $NF}' | xargs npm -g rm

패키지 삭제 메시지 확인 후 node 설치 진행.
출처 : StackOverFlow - Command to remove all npm modules globally

node 설치

curl -fsSL https://deb.nodesource.com/setup_19.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

node 삭제후 계속해서 위 명령어 전체를 복사하여 붙여넣기 후 실행.
아래 출처 사이트에서 최신버전 확인 후 설치.
출처 : Github - nodesource

참조. react-scripts 가 0.9.5로 설치된 package.json

// react-scripts 가 0.9.5로 설치된 package.json
{
  "name": "hello-react1",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "0.9.5"
  },
  "devDependencies": {},
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

참조. react-scripts 가 5.0.1로 설치된 package.json

//node 재설치 후 package.json
{
  "name": "hello-react2",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

끝.

profile
글 남기기

0개의 댓글