mac으로 react-native 실행하는 중 발생한 compile 에러 해결하기

Maliethy·2021년 2월 9일

1. issue

mac에서 rn프로젝트를 git으로 clone받은 후 실행하기위해 프로젝트 ios 폴더에서 npx pod install을 하는데 다음의 에러가 발생했다.

  1. error Could not find "Podfile.lock" at /Users/kangseunghun/Desktop/ksh/sample/ios/Podfile.lock. Did you run "pod install" in iOS directory?

    error Could not find "Podfile.lock" at /Users/cotton/wellwork/front/ios/Podfile.lock. Did you run "pod install" in iOS directory?
    error Could not find the following native modules: RNCMaskedView, RNGestureHandler, RNReanimated, react-native-safe-area-context, RNScreens, RNVectorIcons. Did you forget to run "pod install" ?
    info Found Xcode project "front_RN.xcodeproj"
    info Launching iPhone 11 (iOS 13.4)
    info Building (using "xcodebuild -project front_RN.xcodeproj -configuration Debug -scheme front_RN -destination id=762A352F-C0D1-4F9D-9238-528096B257DB")
    error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening front_RN.xcodeproj. Run CLI with --verbose flag for more details.

팟 라이브러리가 꼬이는 경우인가 싶어 CocoaPods 설치 및 삭제를 보고 팟 삭제를 시도했다.
그러나 npx pod install을 하면 아래의 에러가 나타났다.

error: missing required argument `module|git:/'

  1. npm install --no-optional Missing required argument에서 npm version 이 오래되었을 경우 다음의 에러가 발생할 수 있다고 해서 npm을 update하려고 했다.

npm update를 하니 권한문제가 발생했다.

permission denied, access '/usr/local/lib/node_modules/npm/node_modules/abbrev'

Error: EACCES: permission denied, access '/usr/local/lib/node_modules'에서 sudo chown -R $USER /usr/local/lib/node_modules를 실행하니 원래 맨 아래 두 개는 root, 그밖에는 모두 다른 유저로 권한이 설정되어 있던 것이 내가 새로 만든 계정(아래의 예에서 myuserid)으로 모두 변경되었다.

drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules

drwxrwxr-x 14 deoksu admin 448 2 9 17:37 ..
drwxr-xr-x 8 deoksu wheel 256 10 11 2019 bower
drwxr-xr-x 20 deoksu staff 640 8 16 2016 cordova
drwxr-xr-x 9 deoksu wheel 288 3 29 2020 gatsby-cli
drwxr-xr-x 8 deoksu wheel 256 6 9 2018 http-server
drwxr-xr-x 21 deoksu wheel 672 10 12 2019 ionic
drwxr-xr-x 7 deoksu wheel 224 10 12 2019 n
drwxr-xr-x 24 deoksu wheel 768 10 12 2019 npm

그 후에 아래의 댓글에 다음과 같이 권한을 변경하는 것이 다른 프로그램에도 영향을 줄 수 있는 방법이라는 글을 읽었다. nvm을 설치해 node의 버전을 관리하는 것을 추천한다는 글을 보고 homebrew를 이용해 nvm을 설치했다.

This is not a good solution at all. By running above chown you are at high risk of destroying the permission structure of your entire filesystem.

  1. 그랬더니 $ npm zsh: command not found: nvm가 발생했다.

source ~/.zshrc

위의 명령어로 vi ~/.zshrc로 수정한 환경변수 변경내용을 적용하지 않아서 발생한 문제였고 Mac Catalina zsh에서 nvm not found 해결방법 (bash로 사용하기)의 도움을 받아 nvm을 사용할 수 있게 되었다. nvm으로 npm 14.15.1버전을 설치하고 nvm use 14.15.1를 실행했다. 그러나 이것이 제대로 적용되지 않아 프로젝트에서 npm install을 실행하니 다음의 에러가 발생했다.

  1. Not Found - GET https://registry.npmjs.org/- - Not found 에러를 해결하려고 nvm use명령어를 다시 실행하니 prefix문제가 발생했다.

nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/usr/local"

환경변수 설정에 생긴 문제 같은데 터미널 창에 unset prefix config 명령어를 입력하라해서 입력했더니 nvm use 14.15.1이 잘 적용되었다.

NVM is not compatible with the npm config "prefix" option warning (Mac OS) + npm ERR! code ELIFECYCLE npm ERR! errno 11 npm ERR! Exit status 11

  1. 다시 프로젝트로 돌아가 npx pod install를 실행하니 error: missing required argument module|git:/ 가 다시 발생했다.
    error: missing required argument module|git:/를 읽어보니
    아무래도 Cocoapods를 설치할 때 터미널에 git 명령어를 붙여 실행하라고 하는 명령어를 실행한 것이 문제가 된 것이 아닌가 싶어 내일 다시 확인해보기로 했다.

mac주인이 빌려주면서 업데이트를 하지 말라고 했다던데 내가 오류해결을 위해 시도한 위의 설정들이 문제를 일으켰을 것 같아 걱정된다.

  1. cocoapads를 지우고 다시 설치하려고 하니 설치가 안되어 있었다!

    cotton@zaffre ~ % sudo gem uninstall cocoapods
    Password:
    Gem 'cocoapods' is not installed

아주 간단한 문제였는데 정말 뺑뺑 돌았던 것이다ㅜㅠ cocoapods를 다시 설치하니 프로젝트 폴더에서 npx pod install이 성공적으로 실행되었다.

Pod installation complete! There are 53 dependencies from the Podfile and 44 total pods installed.

  1. 대부분 pod update를 하면 문제가 해결된다고 했으나 여전히 컴파일 에러가 발생했다.
    [RN 에러노트🔥] The following build commands failed: CompileC /Users/dody/Library/Developer/Xcode/DerivedData/oheadline_client-bntjzlxfwpoksjdlhzqejhufjwdn/Buil...

cd ios
pod deintegrate
pod update

  1. 현재 프로젝트 파일만의 문제인가 싶어서 새로 react-native-cli init을 통해 새 프로젝트를 만들었으나 똑같은 컴파일 에러가 발생했다.

    The following build commands failed: CompileC /Users/cotton/Library/Developer/Xcode/DerivedData/front_RN-alfyhulildmptygurvmqovoawgnv/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper-Folly.build/Objects-normal/x86_64/VirtualEventBase.o /Users/cotton/wellwork/front/ios/Pods/Flipper-Folly/folly/io/async/VirtualEventBase.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (1 failure)
    The following build commands failed: CompileC /Users/cotton/Library/Developer/Xcode/DerivedData/firstApp-hgobdqvmotntszcxprrncggaopkb/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper-Folly.build/Objects-normal/x86_64/VirtualEventBase.o /Users/cotton/firstApp/ios/Pods/Flipper-Folly/folly/io/async/VirtualEventBase.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler (1 failure)

  1. 지금 가장 의심되는 것은 프로젝트 폴더가 있던 dir에 프로젝트와 관련없는 다른 node_modules폴더가 있던 것이다. 경로 설정을 아래의 해결책처럼 바꿔줘야 프로젝트 폴더의 node_modules를 인식할 수 있는 게 아닌가 싶었다. xcode에서 Index Datastore의 경로를 바꿔주지 않았더니 역시 컴파일 에러가 떴다.

After I changed DerivedData path in project settings the react-native run-ios command worked for me.
Open Xcode project -> File -> Project Settings -> Under Derived Data click Advanced -> Change 3 paths to begin with <your_project_directory>/build, for example:
Products: /Users/szx/Desktop/MyApp/ios/build/Build/Products
Intermediates: /Users/szx/Desktop/MyApp/ios/build/Build/Intermediates.noindex
Index Datastore: /Users/szx/Desktop/MyApp/ios/build/Index/DataStore

React native run-ios 0.57.x is broken #21741

  1. xcode의 디버깅 메세지를 보면 swift 버전 문제가 발생해서라고 한다.
    Convert to Current Swift Syntax Failed - “No such module” (Swift 4, Xcode 9)
    최신 버전을 설치하려면 cocoapods를 삭제하고 아래처럼 업데이트를 해보려 했다.
    How to remove CocoaPods from a project?

  2. 다시 새로운 rn 프로젝트를 만들어도 DerivedData를 찾지 못하는 에러 발생

    ld: warning: directory not found for option '-L/Users/deoksu/Library/Developer/Xcode/DerivedData/front_RN-gqeoithpjkknuqaobpogfwrfrcbw/Build/Intermediates.noindex/SwiftMigration/front_RN/Products/Debug-iphonesimulator/Flipper'
    ld: warning: directory not found for option '-L/Users/deoksu/Library/Developer/Xcode/DerivedData/front_RN-gqeoithpjkknuqaobpogfwrfrcbw/Build/Intermediates.noindex/SwiftMigration/front_RN/Products/Debug-iphonesimulator/Flipper-Folly'
    ld: warning: directory not found for option '-L/Users/deoksu/Library/Developer/Xcode/DerivedData/front_RN-gqeoithpjkknuqaobpogfwrfrcbw/Build/Intermediates.noindex/SwiftMigration/front_RN/Products/Debug-iphonesimulator/Flipper-RSocket'
    ld: warning: directory not found for option '-L/Users/deoksu/Library/Developer/Xcode/DerivedData/front_RN-gqeoithpjkknuqaobpogfwrfrcbw/Build/Intermediates.noindex/SwiftMigration/front_RN/Products/Debug-iphonesimulator/FlipperKit'
    ld: file not found: /Users/deoksu/Library/Developer/Xcode/DerivedData/front_RN-gqeoithpjkknuqaobpogfwrfrcbw/Build/Intermediates.noindex/SwiftMigration/front_RN/Products/Debug-iphonesimulator/front_RN.app/front_RN

[iOS Xcode] React-Native build failed in Xcode with library not found in RN 0.60.5 #26106에서 xcode generals setting에 들어가보니 deployment info에 mac이 체크되어 있지 않아서 수정했으나 여전히 에러ㅜㅠ

2. solution

ios/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder. 를 키워드로 구글링해보니
React Native - npx react-native run-ios doesn't work after initializing the project
에서
Podfile의 use_flipper!({ 'Flipper-Folly' => '2.3.0' })을 수정하라는 방법으로 해결했다!

use_flipper!({ 'Flipper-Folly' => '2.3.0' })
post_install do |installer|
fix_deployment_target(installer)
end

참고로 아래의 코드는 'IPHONEOS_DEPLOYMENT_TARGET'에 대한 warning을 해결해준다.

def fix_deployment_target(installer)
  return if !installer
  project = installer.pods_project
  project_deployment_target = project.build_configurations.first.build_settings['IPHONEOS_DEPLOYMENT_TARGET']

  puts "Make sure all pods deployment target is #{project_deployment_target.green}"
  project.targets.each do |target|
    puts "  #{target.name}".blue
    target.build_configurations.each do |config|
      old_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
      new_target = project_deployment_target
      next if old_target == new_target
      puts "    #{config.name}: #{old_target.yellow} -> #{new_target.green}"
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = new_target
    end
  end
end
end

드디어 성공!!

info Found Xcode workspace "front_RN.xcworkspace"
info Building (using "xcodebuild -workspace front_RN.xcworkspace -configuration Debug -scheme front_RN -destination id=D9EA264F-BCCB-4A15-B5FB-BD286161CA5D")
success Successfully built the app
info Installing "/Users/deoksu/Desktop/cotton/wellwork/front/ios/Build/Products/Debug-iphonesimulator/front_RN.app"
info Launching "org.reactjs.native.example.front-RN"
success Successfully launched the app on the simulator

이번 에러를 해결하기위해서는 구체적인 키워드로의 검색이 필요했다. 검색 키워드가 구체적일수록 그에 맞는 적절한 해결방법을 제시하는 글을 찾을 수 있었다. 3일 걸려 해결하니 진짜 눈물난다ㅜㅠ

profile
바꿀 수 있는 것에 주목하자

0개의 댓글