codeQ Blog

Chào mừng mọi người đã đến với codeQ Blog

Cách sửa lỗi react-native: error Command failed with exit code 1. error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65

Đăng vào ngày
Cover Image for Cách sửa lỗi react-native: error Command failed with exit code 1. error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65

Đầu tiên nếu các bạn đã đến bài post này thì chắc các bạn đã gặp cái lỗi tào lao dưới đây:

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The following build commands failed:
Ld /Users/<computer-name>/Library/Developer/Xcode/DerivedData/newApp-asslrbvngvwmjkchdzkjlputjciq/Build/Products/Debug-iphonesimulator/newApp.app/newApp normal
(1 failure)

info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Sau đó bạn cố gắng tạo mới 1 dự án hoàn toàn nhưng cuối cùng vẫn dính lỗi trời đánh này. Khi đó bạn scroll chuột lên trên khoảng 3 cây số qua hằng sa số các warning bạn sẽ gặp cái error sau:

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 newApp.xcworkspace.

Thỉnh thoảng thì react có những cái lỗi khá là siđa, hiển thị lỗi thì giống như đưa thông báo "Tao đang bị lỗi, mày tìm cách fix tao đi, tự mò đi nhé, good luck!".

Sau đây là 3 bước đề fix lỗi này:

1. Đầu tiên bạn mở Terminal ở trong Applications (Mở Finder > Applications > Utilities > Terminal hoặc Shift + Cmd + U). Chuột phải vào Terminal > Get Info.

Chọn check vào ô ☑Open using Rosetta như hình dưới đây:

2. Mở Xcode và làm tương tự như trên (Mở Finder > Applications > Xcode), sau đó Chuột phải vào Xcode > Get Info

Chọn check vào ô ☑Open using Rosetta như hình dưới đây:

3. Bạn vào thư mục ios trong project tìm file Podfile và comment mấy dòng dưới đây:

Tiếp theo bạn Mở Terminal > pod install trong thư mục ios để cài lại các package của ios.

Xong bạn ra ngoài thư mục gốc và chạy yarn ios

Surprise... Ngạc nhiên chưa, như vậy là bạn có thể fix lỗi error Command failed with exit code 1. trên MacOS M1 (Apple Silicon) rồi. Cảm ơn các bạn đã xem, chúc các bạn thành công.