React Native无Expo TypeScript项目初始化失败求助
React Native CLI TypeScript项目初始化失败排查方案
问题场景
作为React Native新手,尝试搭建非Expo的TypeScript项目,执行初始化命令:
npx react-native init MyApp --template react-native-template-typescript
过程中出现错误,终端输出如下:
###### ###### ### #### #### ### ## ### ### ## ## #### ## ## #### ## ## ## ## ## ## ### ### ## ## ######################## ## ###### ### ### ###### ### ## ## ## ## ### ### ## ### #### ### ## ### ## #### ######## #### ## ## ### ########## ### ## ## #### ######## #### ## ### ## ### #### ### ## ### ### ## ## ## ## ### ###### ### ### ###### ## ######################## ## ## ### ### ## ## ## ## ## ## #### ## ## #### ## ## ### ### ## ### #### #### ### ###### ###### Welcome to React Native! Learn once, write anywhere ✔ Downloading template ✔ Copying template ✔ Processing template ✖ Installing Bundler error /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin22/rbconfig.rb:21: warning: Insecure world writable dir /usr/local/mongodb in PATH, mode 040777 ✖ Installing Bundler error Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI QuickStart guide for macOS and iOS. Error: Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI QuickStart guide for macOS and iOS. at createFromTemplate (/Users/phamthanhphuc/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/init/init.js:169:11) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Object.initialize [as func] (/Users/phamthanhphuc/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/init/init.js:222:3) at async Command.handleAction (/Users/phamthanhphuc/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/index.js:140:9) info Run CLI with --verbose flag for more details.
解决步骤
1. 修复Ruby路径权限警告
终端提示的Insecure world writable dir /usr/local/mongodb是目录权限问题,执行以下命令修改权限:
sudo chmod 755 /usr/local/mongodb
2. 配置iOS开发环境
初始化失败的核心原因是iOS环境未正确配置,按以下步骤检查:
- 确保已安装Xcode,且首次打开Xcode时完成了协议同意、组件安装等初始化操作
- 安装CocoaPods(React Native依赖它管理iOS第三方库):
sudo gem install cocoapods - 验证CocoaPods安装成功:
pod --version - 安装Xcode命令行工具(若未安装):
xcode-select --install
3. 重新执行初始化命令
删除已生成的MyApp目录(如果存在),重新运行初始化命令:
npx react-native init MyApp --template react-native-template-typescript
内容的提问来源于stack exchange,提问作者PhucPT
相关产品推荐
相关产品推荐

