IT 기술/[React] Project
[오류] /bin/sh: react-scripts: command not found
Lee Hye Won
2021. 6. 1. 14:28
yarn start 명령으로 프로젝트를 시작하려하면 해당 오류가 빈번하게 발생한다...
~ yarn start
/bin/sh: react-scripts: command not found
그럼 여기서 react-scripts 뭘까
※react-scripts 는 Node.js 의 모듈로서 create-react-app 으로 프로젝트를 생성할 때 함께 설치되는 라이브러리로,
(create-react-app 은 react 프로젝트를 간편하고 빠르게 실행하기 위해 사용한다.)
create-react-app 만을 위해 만들어진 모듈이다.
원래 내가 npm 대신 사용하는 yarn 에는 'start' 라는 명령이 없다. (yarn run 이나 npm start 가 맞음)
어쨌든, yarn start 라는 명령을 내리면 (1) 현재 디렉토리에 package.json 가 있는지 찾아보고 (2) 내가 package.json 의 "scripts" 에 정의한 start 명령을 실행시킨다.
// package.json
"scripts": {
"start": "NODE_PATH=src react-scripts start",
"start:dev": "NODE_PATH=src node scripts/build.js",
"build": "NODE_PATH=src react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
그런데도 '/bin/sh: react-scripts: command not found' 오류가 발생하는 이유는 react-scripts 라이브러리를 현재 디렉토리에서 실행시킬 수 없는 상황이기 때문이다.
react-scripts 은(는) 내부 또는 외부 명령 실행할 수 있는 프로그램 또는 배치 파일이 아닙니다
이럴 땐 일단 react-scripts 라이브러리를 전역에 설치하면 당장의 오류는 해결되나, 권장되는 방법인지는 모르겠다.
~ yarn add global react-scripts
위 방법 외에도 package.json 이 있는 디렉토리에서 아래 명령을 하면 된다고 한다.
~ yarn add react-scripts
~ npm install -save react-scripts
혹은
~ yarn upgrade