[React Native] 빌드 시 PhaseScriptExecution / nvm 에러 해결

xeptember·2023년 1월 31일
0
post-thumbnail

리액트 네이티브 앱 최초 세팅 시 정상적으로 빌드가 잘 되는지 확인하기 위해 yarn ios로 시뮬레이터 실행을 해보는데 오류가 발생했다.

오류메세지가 매우 길고 복잡한데, 대략적으로 살펴보자면

The following build commands failed:
        PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/user/Library/Developer/Xcode/DerivedData/.../Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00015C80.sh (in target 'FBReactNativeSpec' from project 'Pods')
(1 failure)
You need to run `nvm install default` to install and use it.
Command PhaseScriptExecution failed with a nonzero exit code

위와 같은 메세지들을 확인할 수 있었다

PhaseScriptExecution 키워드로 구글링을 해본 결과 /ios 디렉토리에 있는 Podfile 을 수정하고, Podfile.lock를 삭제하고, 다시 pod install로 재설치 하는 방법이 많이 나왔으나, 따라 해본결과 아예 pod install 자체를 실패하고 있었다.

그러던 중 해결 방법을 찾게 되어 추후 동일한 문제 발생 시에 참고하기 위해 작성했다.

우선 nvm 관련 에러가 맞았고, 해결 방안은 아래와 같다.

/node_modules/react-native/scripts/find-node.sh

위 파일의 nvm 부분을 수정해야 한다.

// Before 
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
  # shellcheck source=/dev/null
  . "$HOME/.nvm/nvm.sh" --no-use
  nvm use 2> /dev/null || nvm use default
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
  # shellcheck source=/dev/null
  . "$(brew --prefix nvm)/nvm.sh" --no-use
  nvm use 2> /dev/null || nvm use default
fi
// After
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
    # shellcheck source=/dev/null
    . "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]];      
then
    # shellcheck source=/dev/null
    . "$(brew --prefix nvm)/nvm.sh"   
fi

이후 다시 yarn ios 명령어를 실행하면 빌드에 성공하고 시뮬레이터에서 빌드된 앱을 확인할 수 있었다.

참고 URL
https://stackoverflow.com/questions/66742033/phasescriptexecution-cp-user-error-in-react-native/70309731#70309731

profile
Front-end engineer

0개의 댓글